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

Deliberately throwing your own JavaScript errors

In this section, we will learn how to throw our own JavaScript errors and exceptions. We will briefly cover the syntax of the error functions and commands. It may be a little incomprehensible at this stage to just give you the syntax, but this is necessary. Once you understand how to make use of these commands and reserved words, you will see how you can make use of them to give yourself more specific information (and hence more control) over the types of errors that you can catch and create in the next section. So let us get started with the first reserved word—throw.

The throw statements

throw is a statement that allows you to create an exception or error. It is a bit like the break statement, ...

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