Skip to content

Throwing exceptions with specific values in JavaScript

In JavaScript, throw statement throws a user-defined exception. It can be an expression, values of primitive types or Objects. Here are a few examples.

Advertisements
// throw an exception, expression specifies the value of the exception. eg:

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

Source

See also  Python code snippet - How to change number of steps in tensorflow object detection api?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.