AggregateError

翻译不完整。 请帮助我们翻译这篇文章!

草案
本页尚未完工.

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

AggregateError当多个错误​​需要包装在一个错误中时,对象表示一个错误。

语法

new AggregateError(errors[, message])

参数

errors
错误的描述,默认为空。
message可选
AggregateError错误的提示信息。

描述

一个AggregateError当需要由操作报告多个错误被抛出,例如通过Promise.any(),在传递给它的所有Promise拒绝。

属性

AggregateError.prototype
AggregateError的原

AggregateError 实例

实例属性

AggregateError.prototype.constructor
指定创建实例原型的函数。
AggregateError.prototype.message
错误消息,默认为""
AggregateError.prototype.name
错误名称,默认为"AggregateError"

示例

捕获一个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" ]
});

创建一个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" ]
}

规范

Specification Status Comment
ESNext Promise.any Proposal Stage 3 Draft Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
AggregateErrorChrome Full support 85Edge No support NoFirefox Full support 79IE No support NoOpera No support NoSafari Full support 14WebView Android Full support 85Chrome Android Full support 85Firefox Android Full support 79Opera Android No support NoSafari iOS Full support 14Samsung Internet Android No support Nonodejs No support No
AggregateError() constructorChrome Full support 85Edge No support NoFirefox Full support 79IE No support NoOpera No support NoSafari Full support 14WebView Android Full support 85Chrome Android Full support 85Firefox Android No support NoOpera Android No support NoSafari iOS Full support 14Samsung Internet Android No support Nonodejs No support No

Legend

Full support  
Full support
No support  
No support

相关链接