Error objects
suggest changeRuntime 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);
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents