JavaScript Statements Reference
This example examines input. If the value is wrong, an exception (err) is thrown.
The exception (err) is caught by the catch statement and a custom error message is displayed:
The throw statement throws (generates) an error.
When an error occurs, JavaScript will normally stop, and generate an error message.
The technical term for this is: JavaScript will throw an error.
The throw statement allows you to create a custom error.
The technical term for this is: throw an exception.
The exception can be a JavaScript String, a Number, a Boolean or an Object:
If you use throw together with try and catch, you can control program flow and generate custom error messages..
For more information about JavaScript errors, read our JavaScript Errors Tutorial.
Statement | |||||
---|---|---|---|---|---|
throw | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
expression | Required. The exception to throw. Can be a string, number, boolean or an object |
JavaScript Version: | 1.4 |
---|
JavaScript Tutorial: JavaScript Errors
JavaScript Reference: JavaScript try/catch/finally Statement