--- title: AggregateError slug: Web/JavaScript/Reference/Global_Objects/AggregateError translation_of: Web/JavaScript/Reference/Global_Objects/AggregateError ---
{{JSRef}}{{Draft}}{{SeeCompatTable}}
AggregateError
当多个错误需要包装在一个错误中时,该对象表示一个错误。
new AggregateError(errors[, message])
errors
message
{{Optional_Inline}}一个AggregateError
当需要由操作报告多个错误被抛出,例如通过Promise.any()
,在传递给它的所有Promise
拒绝。
AggregateError.prototype
AggregateError
的原型AggregateError.prototype.constructor
""
。"AggregateError"
。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" ] });
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 | Status | Comment |
---|---|---|
ESNext Promise.any Proposal | Stage 3 Draft | Initial definition. |
{{Compat("javascript.builtins.AggregateError")}}