大网数据广告活动
Web 标准与前端开发

AggregateError() 构造函数

· 52CE 我爱测

**`AggregateError()`** 构造函数创建了一个包装了多个错误对象的单个错误对象。

AggregateError() 构造函数创建了一个包装了多个错误对象的单个错误对象。

语法

new AggregateError(errors)
new AggregateError(errors, message)
new AggregateError(errors, message, options)

AggregateError(errors)
AggregateError(errors, message)
AggregateError(errors, message, options)

[!NOTE] 调用 AggregateError() 可以使用或不使用 new,两种方法都会创建一个新的 AggregateError 实例。

参数

  • errors
    • : 一系列错误对象,实际上可能不是 Error 的实例。
  • message
    • : 一个可选的对错误集合的可读描述。
  • options
    • : 一个具有以下属性的对象:
      • cause
        • : 表示错误的具体原因的属性。当捕捉并重新抛出一个带有更具体或有用的错误信息的错误时,这个属性可以用来传递原始错误。

示例

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

规范

浏览器兼容性

参见

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。