Mega Code Archive

 
Categories / JavaScript Tutorial / Development
 

Throw exception out of a function

< html> <head> <title>Try Catch Example</title> <script type="text/javascript"> function addTwoNumbers(a, b) {     throw new Error("Two numbers are required."); } try {     result = addTwoNumbers(90); } catch (oException) {     alert(oException.message); } </script> </head> <body> </body> </html>