我看到了一个非常特殊(也很奇怪)的错误处理代码,如下所示:
function SomeError(name, message) {
this.name = name;
this.message = message;
this.stack = (new Error()).stack;
}
SomeError.prototype = Object.create(Error.prototype);
承诺捕获:
promise.catch(e => {
throw new SomeError('someName', e.message);
});
我的问题:
有什么合理的理由可以这样做吗?
我想过这样处理:
promise.catch(e => {
e.name = 'my error name';
throw new Error(e);
});