聚合错误 - Javascript
AggregateError - Javascript
我最近注意到了新的 AggregateError
对象 (ECMAScript 2021)。有没有推荐使用的案例或最佳实践?
来自 MDN wiki 的描述:
The AggregateError object represents an error when several errors need to be wrapped in a single error. It is thrown when multiple errors need to be reported by an operation, for example by Promise.any(), when all promises passed to it reject.
因此,只要描述合适就使用它 - 如果您想一次抛出多个错误。
我最近注意到了新的 AggregateError
对象 (ECMAScript 2021)。有没有推荐使用的案例或最佳实践?
来自 MDN wiki 的描述:
The AggregateError object represents an error when several errors need to be wrapped in a single error. It is thrown when multiple errors need to be reported by an operation, for example by Promise.any(), when all promises passed to it reject.
因此,只要描述合适就使用它 - 如果您想一次抛出多个错误。