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