The Error Object - Javascript Language Basics

Javascript examples for Language Basics:Introduction

Introduction

PropertyDescription Returns
message A description of the error condition. string
nameThe name of the error. This is Error, by default. string
number The error number, if any, for this kind of error. number

The catch clause can recover from the error.

To be executed whether or not there has been an error, place them in the optional finally clause.

Demo Code

ResultView the demo in separate window

      <!DOCTYPE HTML>
      <html>
          <head>
              <title>Example</title>
          </head>
          <body>
              <script type="text/javascript">
                  try {/*from   w ww . j a  v  a 2 s. c  o m*/
                      var myArray;
                      for (var i = 0; i < myArray.length; i++) {
                          document.writeln("Index " + i + ": " + myArray[i]);
                      }
                  } catch (e) {
                      document.writeln("Error: " + e);
                  } finally {
                      document.writeln("Statements here are always executed");
                  }
              </script>
          </body>
</html>

Related Tutorials