このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

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月.

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

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

SuppressedError と比較すると、AggregateError は無関係のエラーのリストを表すのに対し、 SuppressedError は他のエラーを処理中に発生したエラーを表します。

AggregateErrorError のサブクラスです。

コンストラクター

AggregateError()

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

インスタンスプロパティ

親である Error から継承したインスタンスプロパティもあります

以下のプロパティは AggregateError.prototype に定義されており、すべての AggregateError インスタンスで共有されます。

AggregateError.prototype.constructor

このインスタンスオブジェクトを生成したコンストラクター関数です。AggregateError インスタンスでは、初期値は AggregateError コンストラクターです。

AggregateError.prototype.name

エラーの型の名前を表します。AggregateError.prototype.name では、初期値は "AggregateError" です。

以下のプロパティは、それぞれの AggregateError インスタンス自身のプロパティです。

errors

まとめられたエラーを表す配列です。

インスタンスメソッド

親である Error からインスタンスメソッドを継承しています

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

ブラウザーの互換性

関連情報