JavaScript throw Statement

This example examines input

Definition and Usage

The throw statement allows you to create a custom error.

The throw statement throws (generates) an error.

The technical term for this is:

The throw statement throws an exception.

The exception can be a JavaScript String, a Number, a Boolean or an Object:

throw "Too big";  // throw a text
throw 500;        // throw a number
throw false;      // throw a boolean
throw person;     // throw an object

Note

Using throw with try and catch, lets you control program flow and generate custom error messages.

See Also:

The JavaScript try...catch...finally

JavaScript Error Object

JavaScript Errors Tutorial

Syntax

throw expression;

Parameters

Parameter Description
expression Required.
The exception to throw.
Can be a string, number, boolean, or an object

Browser Support

break is an ECMAScript3 (ES3) feature.

ES3 (JavaScript 1999) is fully supported in all browsers:

Chrome IE Edge Firefox Safari Opera
Yes Yes Yes Yes Yes Yes