O'Reilly logo

JavaScript Testing by Liang Yuxian Eugene

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Trapping errors by using built-in objects

In this section, we'll briefly describe what each type of built-in object is, along with its syntax, before we show some examples of how each of the built-in objects work. Do take note that the alert messages, which we will be using sparingly in the examples, are based on the Firefox browser. If you try the code on Internet Explorer, you might see different error messages.

The Error object

An Error is a generic exception, and it accepts an optional message that provides details of the exception. We can use the Error object by using the following syntax:

new Error(message); // message can be a string or an integer

Here's an example that shows the Error object in action. The source code for this example can ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required