Creating Error object

suggest change

new Error(message)

new Error(message) creates an error and sets its message property. message is usually a string. If it is not a string, it is converted with ToString (for a normal object, that calls .toString()).

const err = new Error('The error message');
console.log(err.message);
The error message

Every error has a stack trace. It includes the message and the call site where the error was created. The output above is only err.message, not the stack. The stack is captured when the error is constructed. In Node.js, these two lines both print that stack:

console.log(err);
console.log(err.stack);

Feedback about page:

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



Table Of Contents