AggregateError() Konstruktor
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.
Der AggregateError()
Konstruktor erstellt AggregateError
Objekte.
Syntax
new AggregateError(errors)
new AggregateError(errors, message)
new AggregateError(errors, message, options)
AggregateError(errors)
AggregateError(errors, message)
AggregateError(errors, message, options)
Note:
AggregateError()
kann mit oder ohnenew
aufgerufen werden. Beide erstellen eine neue Instanz vonAggregateError
.
Parameter
errors
-
Ein Iterable von Fehlern, die möglicherweise keine
Error
Instanzen sind. message
Optional-
Eine optionale, lesbare Beschreibung des Aggregatfehlers.
options
Optional-
Ein Objekt, das die folgenden Eigenschaften hat:
cause
Optional-
Eine Eigenschaft, die die spezifische Ursache des Fehlers angibt. Beim Abfangen und erneuten Auslösen eines Fehlers mit einer spezifischeren oder nützlicheren Fehlermeldung kann diese Eigenschaft verwendet werden, um den ursprünglichen Fehler weiterzugeben.
Beispiele
Erstellen eines 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" ]
}
Spezifikationen
Specification |
---|
ECMAScript Language Specification # sec-aggregate-error-constructor |
Browser-Kompatibilität
BCD tables only load in the browser