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