function myFunc() { var a = 100; try { alert("Value of variable a is : " + a ); } catch ( e ) { alert("Error: " + e.description );

Click the following to see the result:

"> function myFunc() { var a = 100; try { alert("Value of variable a is : " + a ); } catch ( e ) { alert("Error: " + e.description );

Click the following to see the result:

">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

JavaScript - Errors & Exceptions Handling

Similar presentations


Presentation on theme: "JavaScript - Errors & Exceptions Handling"— Presentation transcript:

1 JavaScript - Errors & Exceptions Handling
Three types of errors in programming: Syntax Errors Runtime Errors Logical Errors try...catch...finally Statement The try statement -test a block of code for errors. The catch statement -handle the error. The throw statement -create custom errors. The finally statement -execute code, after try and catch, regardless of the result.

2 <html> <head> <script type="text/javascript"> function myFunc() { var a = 100; try { alert("Value of variable a is : " + a ); } catch ( e ) { alert("Error: " + e.description ); </script> </head> <body> <p>Click the following to see the result:</p> <form> <input type="button" value="Click Me" onclick="myFunc();" /> </form> </body> </html>

3

4 <script type="text/javascript"> function myFunc() { var a = 100;
</head> <body> <p>Click the following to see the result:</p> <form> <input type="button" value="Click Me" onclick="myFunc();" /> </form> </body> </html> <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>


Download ppt "JavaScript - Errors & Exceptions Handling"

Similar presentations


Ads by Google