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.

* Some parts of this feature may have varying levels of support.

AggregateError オブジェクトは、複数のエラーを 1 つのエラーにまとめる必要があるときのエラーを表します。これは一つの操作で複数のエラーを報告する必要があるときに発生します。例えば Promise.any() において、渡されたすべてのプロミスが拒否された場合などです。

コンストラクター

AggregateError()

新しい AggregateError オブジェクトを生成します。

インスタンスプロパティ

AggregateError.prototype.message

エラーメッセージで、既定値は "" です。

AggregateError.prototype.name

エラー名で、既定値は AggregateError です。

AggregateError: errors

AggregateError のインスタンスが作成された反復可能オブジェクトを本質的に反映した配列です。例えば、 AggregateErrorAggregateError() コンストラクターを用いて生成された場合、最初の引数として渡された反復可能オブジェクトから生成される配列になります。

AggregateError の捕捉

js
Promise.any([Promise.reject(new Error("some error"))]).catch((e) => {
  console.log(e instanceof AggregateError); // true
  console.log(e.message); // "All Promises rejected"
  console.log(e.name); // "AggregateError"
  console.log(e.errors); // [ Error: "some error" ]
});

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® 2025 Language Specification
# sec-aggregate-error-objects

ブラウザーの互換性

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
AggregateError() constructor
errors
AggregateError is serializable

Legend

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

Full support
Full support
No support
No support
See implementation notes.

関連情報