AggregateError() 构造函数
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2020.
AggregateError()
构造函数创建了一个包装了多个错误对象的单个错误对象。
语法
js
new AggregateError(errors)
new AggregateError(errors, message)
new AggregateError(errors, message, options)
AggregateError(errors)
AggregateError(errors, message)
AggregateError(errors, message, options)
备注:调用 AggregateError()
可以使用或不使用 new
,两种方法都会创建一个新的 AggregateError
实例。
参数
示例
创建 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 Language Specification # sec-aggregate-error-constructor |
浏览器兼容性
BCD tables only load in the browser