Mega Code Archive

 
Categories / JavaScript Tutorial / Development
 

Catch exception throwed from assert function

< html>     <head>         <title>Try Catch Example</title>         <script type="text/javascript">                 function assert(bCondition, sErrorMessage) {                     if (!bCondition) {                         throw new Error(sErrorMessage);                     }                 }                 try {                     assert(1 == 2, "Two numbers are required.");                 } catch (oException) {                     alert(oException.message);      //outputs "Two numbers are required."                 }         </script>     </head>     <body>     </body> </html>