AggregateError

AggregateError object represents an error when several errors need to be wrapped in a single error. It is thrown when multiple errors need to be reported by an operation, for example by Promise.any() , when all promises passed to it reject.

构造函数

AggregateError()
创建新的 AggregateError 对象。

实例特性

AggregateError.prototype.message
Error message, defaults to "" .
AggregateError.prototype.name
Error name, defaults to AggregateError .

范例

Catching an AggregateError

Promise.any([
  Promise.reject(new Error("some error")),
]).catch(e => {
  console.log(e instanceof AggregateError); // true
  console.log(e.message);                   // "All Promises rejected"
  console.log(e.name);                      // "AggregateError"
  console.log(e.errors);                    // [ Error: "some error" ]
});
					

Creating an AggregateError

try {
  throw new AggregateError([
    new Error("some error"),
  ], 'Hello');
} catch (e) {
  console.log(e instanceof AggregateError); // true
  console.log(e.message);                   // "Hello"
  console.log(e.name);                      // "AggregateError"
  console.log(e.errors);                    // [ Error: "some error" ]
}
					

规范

规范
Promise.any
The definition of 'AggregateError' in that specification.

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
AggregateError Chrome 85 Edge No Firefox 79 IE No Opera No Safari 14 WebView Android 85 Chrome Android 85 Firefox Android No Opera Android No Safari iOS 14 Samsung Internet Android No nodejs No
AggregateError() 构造函数 Chrome 85 Edge No Firefox 79 IE No Opera No Safari 14 WebView Android 85 Chrome Android 85 Firefox Android No Opera Android No Safari iOS 14 Samsung Internet Android No nodejs No

图例

完整支持
完整支持
不支持
不支持

另请参阅

Metadata