--- title: AggregateError slug: Web/JavaScript/Reference/Global_Objects/AggregateError tags: - AggregateError - Class - Experimental - Interface - JavaScript - クラス translation_of: Web/JavaScript/Reference/Global_Objects/AggregateError --- <div>{{JSRef}}</div> <p><code><strong>AggregateError</strong></code> オブジェクトは、複数のエラーを1つのエラーにまとめる必要があるときのエラーを表します。これは一つの操作で複数のエラーを報告する必要があるときに発生します。例えば {{JSxRef("Promise.any()")}} において、渡されたすべてのプロミスが拒否された場合などです。</p> <h2 id="Constructor" name="Constructor">コンストラクター</h2> <dl> <dt>{{jsxref("Global_Objects/AggregateError/AggregateError", "AggregateError()")}}</dt> <dd>新しい <code>AggregateError</code> オブジェクトを生成します。</dd> </dl> <h2 id="Instance_properties" name="Instance_properties">インスタンスプロパティ</h2> <dl> <dt>{{JSxRef("Error.prototype.message", "AggregateError.prototype.message")}}</dt> <dd>エラーメッセージで、既定値は <code>""</code> です。</dd> <dt>{{JSxRef("Error.prototype.name", "AggregateError.prototype.name")}}</dt> <dd>エラー名で、既定値は <code>AggregateError</code> です。</dd> </dl> <h2 id="Examples" name="Examples">例</h2> <h3 id="Catching_an_AggregateError" name="Catching_an_AggregateError">AggregateError の捕捉</h3> <pre class="brush: js; notranslate">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" ] }); </pre> <h3 id="Creating_an_AggregateError" name="Creating_an_AggregateError">AggregateError の生成</h3> <pre class="brush: js; notranslate">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" ] } </pre> <h2 id="Specifications" name="Specifications">仕様書</h2> <table class="standard-table"> <thead> <tr> <th scope="col">仕様書</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('Promise.any', '#sec-aggregate-error-object-structure', 'AggregateError')}}</td> </tr> </tbody> </table> <h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> <div> <p>{{Compat("javascript.builtins.AggregateError")}}</p> </div> <h2 id="See_also" name="See_also">関連情報</h2> <ul> <li>{{JSxRef("Error")}}</li> </ul>