error.message


error.message 属性是通过调用 new Error(message) 设置的错误的字符串描述。传递给构造函数的 message 也会出现在 Error 的堆栈跟踪的第一行,但是在创建 Error 对象后更改此属性可能不会更改堆栈跟踪的第一行(例如,当之前读取 error.stack 时 此属性已更改)。

¥The error.message property is the string description of the error as set by calling new Error(message). The message passed to the constructor will also appear in the first line of the stack trace of the Error, however changing this property after the Error object is created may not change the first line of the stack trace (for example, when error.stack is read before this property is changed).

const err = new Error('The message');
console.error(err.message);
// Prints: The message