blob: d9e0e018e9ebd4bb237e3bfdd5e8798a8758f2e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
---
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>
<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div>
<p>{{Compat("javascript.builtins.AggregateError")}}</p>
</div>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li>{{JSxRef("Error")}}</li>
</ul>
|