AggregateError() コンストラクター
Baseline
広く利用可能
この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。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" ]
}
仕様書
| 仕様書 |
|---|
| ECMAScript® 2027 Language Specification> # sec-aggregate-error-constructor> |