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

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























           टा  3: try-catch-finally का उपयोग करके  एरर ह डिलंग कर

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

           2  िन िल खत कोड िलख
              <html >

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

              <body>
              <script>

              try {
              // Code that may throw an error
              let x = 1;

              let y = x + z; // ReferenceError: z is not defined
              console.log(“This line will not be executed if an error occurs.”);
              }

              catch (error)
              {
              // Handle the error

              console.error(“An error occurred:”, error.message); // Output: An error   occurred: z is not defined
              }
              finally

              {
              // Code that runs regardless of whether an error occurred or not
              console.log(“This line will always be executed.”);

              }
              </script>

              </body>
              </html>



                                                           174

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