AggregateError() コンストラクター
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2020年9月.
AggregateError() コンストラクターは AggregateError オブジェクトを生成します。
構文
js
new AggregateError(errors)
new AggregateError(errors, message)
new AggregateError(errors, message, options)
AggregateError(errors)
AggregateError(errors, message)
AggregateError(errors, message, options)
メモ:
AggregateError() は new があってもなくても呼び出せます。どちらも新しい AggregateError インスタンスを生成します。
引数
errors-
エラーの反復可能オブジェクトであり、実際の
Errorインスタンス合ってはなりません。 message省略可-
オプションで、統合エラーの人間可読な説明です。
options省略可-
次のプロパティを持つオブジェクトです。
cause省略可-
エラーの特定の原因を示すプロパティです。 より具体的または有用なエラーメッセージでエラーを捕捉し再発生させる場合、このプロパティを使用して元のエラーを渡すことができます。
例
>AggregateError の作成
js
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" ]
}
仕様書
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-aggregate-error-constructor> |