The stack
property only exists on Error
objects.(stack
属性仅存在于Error
对象上。)
The first parameter of the Error
constructor is a string though, so if you pass an object to it it'll be stringified.(但是, Error
构造函数的第一个参数是字符串,因此,如果将对象传递给它,它将被字符串化。) You could do(你可以做)
throw Object.assign(new Error("message"), {
// properties
});
to throw an error object with custom properties.(抛出带有自定义属性的错误对象。) 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…