JavaScript code to show how to use a throw statement

JavaScript code to show how to use a throw statement



. <html>
      <head>
       <script type="text/javascript">
         <!--
            function myFunc()
            {
               var a = 100;
               var b = 0;
                 try{
                  if ( b == 0 ){
                     throw( "Divide by zero error." ); 
                  }
                  else
                  {
                     var c = a / b;
                  }
               }
                   catch ( e ) {
                  alert("Error: " + e );
               }
            }
         //-->
      </script>
         </head>
      <body>
      <p>Click the following to see the result:</p>
            <form>
         <input type="button" value="Click Me" onclick="myFunc();" />
      </form>
      
   </body>
</html>

Comments

Popular posts from this blog

Artificial Intelligence

The taxonomy of CASE Tools

Zoho Second round - adding a digit to all the digits of a number