The AggregateError()
constructor creates an error for several errors that need to be wrapped in a single error.
AggregateError() constructor
Syntax
new AggregateError(errors) new AggregateError(errors, message)
Parameters
-
errors
-
An iterable of errors, may not actually be
Error
instances. -
message
Optional -
An optional human-readable description of the aggregate error.
Examples
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
Browser compatibility
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
|
See also
© 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/AggregateError