--- title: AggregateError slug: Web/JavaScript/Reference/Global_Objects/AggregateError tags: - AggregateError - Class - Experimental - Interface - JavaScript - クラス translation_of: Web/JavaScript/Reference/Global_Objects/AggregateError ---
{{JSRef}}

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

コンストラクター

{{jsxref("Global_Objects/AggregateError/AggregateError", "AggregateError()")}}
新しい AggregateError オブジェクトを生成します。

インスタンスプロパティ

{{JSxRef("Error.prototype.message", "AggregateError.prototype.message")}}
エラーメッセージで、既定値は "" です。
{{JSxRef("Error.prototype.name", "AggregateError.prototype.name")}}
エラー名で、既定値は AggregateError です。

AggregateError の捕捉

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 の生成

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" ]
}

仕様書

仕様書
{{SpecName('Promise.any', '#sec-aggregate-error-object-structure', 'AggregateError')}}

ブラウザーの互換性

{{Compat("javascript.builtins.AggregateError")}}

関連情報