Page 189 - CITS - CSA - TP (Volume 1) - Hindi
P. 189

कंप्यूटर सॉफ्टवेयर एप्लीकेशन- CITS


















           टा  2: try-catch और throw का उपयोग करके  एरर ह  िडंग कर ।

           1  टे  एिडटर ओपन कर

           2  िन िल खत कोड िलख

              <html >
              <head>
              <title> Object Literal Notation </title>
              </head>
              <body>

              <script>
              function divide(a, b)
              {
              if (b === 0)
              {
              throw new Error(“Division by zero is not allowed”);
              }

              return a / b;
              }
              try
              {

              console.log(divide(10, 0));
              }
              catch (error)
              {
              console.error(“An error occurred:”, error.message);
              }
              </script>

              </body>
              </html>
           3   ो ाम को .html फ़ाइल के   प म  सेव कर

           4  वेब  ाउज़र से html फ़ाइल ओपन कर ।

           5   ाउज़र कं सोल टैब पर जाएँ  और आउटपुट की वेरीफाई कर ।




                                                           173

                                     CITS : IT & ITES - कं  ूटर सॉ वेयर ए ीके शन - अ ास 45
   184   185   186   187   188   189   190   191   192   193   194