Repository navigation
Expand file tree
/
Copy pathindex.md
More file actions
78 lines (54 loc) · 3.11 KB
/
Copy pathindex.md
File metadata and controls
78 lines (54 loc) · 3.11 KB
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
---
title: AggregateError
slug: Web/JavaScript/Reference/Global_Objects/AggregateError
l10n:
sourceCommit: 1d2e1875bdfdd2fb8d0806535220bbd56d3a091d
---
**`AggregateError`** オブジェクトは、複数のエラーを 1 つのエラーにまとめる必要があるときのエラーを表します。これは一つの操作で複数のエラーを報告する必要があるときに発生します。例えば {{jsxref("Promise.any()")}} において、渡されたすべてのプロミスが拒否された場合などです。
{{jsxref("SuppressedError")}} と比較すると、`AggregateError` は無関係のエラーのリストを表すのに対し、 `SuppressedError` は他のエラーを処理中に発生したエラーを表します。
`AggregateError` は {{jsxref("Error")}} のサブクラスです。
## コンストラクター
- {{jsxref("AggregateError/AggregateError", "AggregateError()")}}
- : 新しい `AggregateError` オブジェクトを生成します。
## インスタンスプロパティ
_親である {{jsxref("Error")}} から継承したインスタンスプロパティもあります_。
以下のプロパティは `AggregateError.prototype` に定義されており、すべての `AggregateError` インスタンスで共有されます。
- {{jsxref("Object/constructor", "AggregateError.prototype.constructor")}}
- : このインスタンスオブジェクトを生成したコンストラクター関数です。`AggregateError` インスタンスでは、初期値は {{jsxref("AggregateError/AggregateError", "AggregateError")}} コンストラクターです。
- {{jsxref("Error/name", "AggregateError.prototype.name")}}
- : エラーの型の名前を表します。`AggregateError.prototype.name` では、初期値は `"AggregateError"` です。
以下のプロパティは、それぞれの `AggregateError` インスタンス自身のプロパティです。
- {{jsxref("AggregateError/errors", "errors")}}
- : まとめられたエラーを表す配列です。
## インスタンスメソッド
_親である {{jsxref("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" ]
}
```
## 仕様書
{{Specifications}}
## ブラウザーの互換性
{{Compat}}
## 関連情報
- [`AggregateError` の `core-js` におけるポリフィル](https://github.com/zloirock/core-js#ecmascript-promise)
- [es-shims による `AggregateError` のポリフィル](https://www.npmjs.com/package/es-aggregate-error)
- {{jsxref("Error")}}
- {{jsxref("Promise.any")}}