AggregateError

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

草案
本页尚未完工.

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

The AggregateError object represents an error when several errors need to be wrapped in a single error.

Syntax

new AggregateError(errors[, message])

Parameters

errors
An iterable of errors, may not actually be Error instances.
message可选
An optional human-readable description of the aggregate error.

Description

An AggregateError is thrown when multiple errors need to be reported by an operation, for example by Promise.any(), when all promises passed to it reject.

Properties

AggregateError.prototype
The AggregateError prototype.

AggregateError instances

Instance properties

AggregateError.prototype.constructor
Specifies the function that created an instance's prototype.
AggregateError.prototype.message
Error message, defaults to "".
AggregateError.prototype.name
Error name, defaults to "AggregateError".
AggregateError.prototype.name
The Array of errors which caused this AggregateError to be thrown. Each access to this property causes a new Array to be created.

Examples

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" ]
}

Specifications

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

Browser compatibility

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 No support NoOpera 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

See also