The 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.
The 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()
Creates a new AggregateError
object.
AggregateError.prototype.message
Error message. Inherited from Error
.
AggregateError.prototype.name
Error name. Inherited from Error
.
AggregateError.prototype.cause
Error cause. Inherited from Error
.
AggregateError.prototype.errors
An array that essentially reflects the iterable with which the AggregateError
was instantiated; for example, if the AggregateError
was created using the AggregateError()
constructor, an array produced from whatever iterable was passed to the constructor as its first argument.
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" ] });
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" ] }
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | Deno | Node.js | |
AggregateError |
85 |
85 |
79 |
No |
71 |
14 |
85 |
85 |
79 |
60 |
14 |
14.0 |
1.2 |
15.0.0 |
AggregateError |
85 |
85 |
79 |
No |
71 |
14 |
85 |
85 |
79 |
60 |
14 |
14.0 |
1.2 |
15.0.0 |
serializable_object |
No |
No |
103
Serialized properties:
name , message , cause , errors . |
No |
No |
No |
No |
No |
103
Serialized properties:
name , message , cause , errors . |
No |
No |
No |
No |
No |
© 2005–2022 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError