Javascript examples for Language Basics:Introduction
JavaScript uses the try...catch statement to deal with errors.
Handling an Exception
<!DOCTYPE HTML> <html> <head> <title>Example</title> </head> <body> <script type="text/javascript"> try {//from w w w. j ava 2 s .co m var myArray; for (var i = 0; i < myArray.length; i++) { document.writeln("Index " + i + ": " + myArray[i]); } } catch (e) { document.writeln("Error: " + e); } </script> </body> </html>