聚合错误:errors

AggregateError 实例的 errors 数据属性包含一个表示聚合错误的数组。

¥The errors data property of an AggregateError instance contains an array representing the errors that were aggregated.

¥Value

一个 Array 包含与作为 AggregateError() 构造函数的第一个参数传递的可迭代顺序相同的值。

¥An Array containing values in the same order as the iterable passed as the first argument of the AggregateError() constructor.

Property attributes of 聚合错误:errors
Writable yes
Enumerable no
Configurable yes

示例

¥Examples

使用错误

¥Using errors

js
try {
  throw new AggregateError(
    // An iterable of errors
    new Set([new Error("some error"), new Error("another error")]),
    "Multiple errors thrown",
  );
} catch (err) {
  console.log(err.errors);
  // [
  //   Error: some error,
  //   Error: another error
  // ]
}

规范

Specification
ECMAScript Language Specification
# sec-aggregate-error

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看