Completion requirements
Description
Use the throw
statement to throw an exception. When you throw an
exception, expression
specifies the value of the exception. Each
of the following throws an exception:
throw 'Error2'; // generates an exception with a string value throw 42; // generates an exception with the value 42 throw true; // generates an exception with the value true throw new Error('Required'); // generates an error object with the message of Required
Also note that the throw
statement is affected by
automatic semicolon insertion (ASI)
as no line terminator between the throw
keyword and the expression is allowed.