Constructeur AggregateError()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2020.

Le constructeur AggregateError() permet de créer une erreur qui agrège plusieurs erreurs.

Syntaxe

js
new AggregateError(erreurs);
new AggregateError(erreurs, message);

Paramètres

erreurs

Un objet itérable contenant des erreurs (qui peuvent ne pas être des instances de Error).

message Facultatif

Une description optionnelle, compréhensible par un humain, de l'erreur agrégée.

Exemples

Créer une exception AggregateError

js
try {
  throw new AggregateError([new Error("une erreur")], "Coucou");
} catch (e) {
  console.log(e instanceof AggregateError); // true
  console.log(e.message); // "Coucou"
  console.log(e.name); // "AggregateError"
  console.log(e.errors); // [ Error: "une erreur" ]
}

Spécifications

Specification
ECMAScript® 2025 Language Specification
# sec-aggregate-error-constructor

Compatibilité des navigateurs

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
AggregateError() constructor

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Voir aussi