Error objects

suggest change

Runtime errors in JavaScript are instances of the Error object. The Error object can also be used as-is, or as the base for user-defined exceptions. You can throw any value, including a string, but an Error or one of its subclasses keeps a stack trace. String throws do not.

The first parameter to the Error constructor is the human-readable error message. You should try to always specify a useful error message of what went wrong, even if additional information can be found elsewhere.

try {
   throw new Error('Useful message');
} catch (error) {
   console.log('Something went wrong! ' + error.message);
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents