Movatterモバイル変換


[0]ホーム

URL:


  1. 面向开发者的 Web 技术
  2. JavaScript
  3. JavaScript 参考
  4. JavaScript 标准内置对象
  5. AggregateError

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in EnglishAlways 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 对象代表了包装了多个错误对象的单个错误对象。当一个操作需要报告多个错误时,例如Promise.any(),当传递给它的所有承诺都被拒绝时,就会抛出该错误。

AggregateErrorError 的子类。

构造函数

AggregateError()

创建一个新的AggregateError 对象

实例属性

从父类Error 中继承实例属性。

以下属性在AggregateError.prototype 上定义,并由所有AggregateError 实例共享。

AggregateError.prototype.constructor

创建实例对象的构造函数。对于AggregateError 实例来说,初始值为AggregateError 构造函数。

AggregateError.prototype.name

代表了错误类型的名称,对于AggregateError.prototype.name 来说,初始值为"AggregateError"

这些属性是每个AggregateError 实例的自有属性。

errors

一个数组,基本上反映了AggregateError 实例化时使用的迭代器;例如,如果AggregateError 是用AggregateError() 构造函数创建的,则作为第一个参数传递给构造函数的任何迭代器生成的数组。

实例方法

从父类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

浏览器兼容性

参见

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp