AggregateError
åºçº¿
广æ³å¯ç¨
èª 2020å¹´9æ èµ·ï¼æ¤ç¹æ§å·²å¨ä¸»æµæµè§å¨ä¸å¾å°æ¯æï¼å¯å¨å¤§å¤æ°è®¾å¤åæµè§å¨çæ¬ä¸æ£å¸¸ä½¿ç¨ã
AggregateError 对象代表äºå
è£
äºå¤ä¸ªé误对象çå个é误对象ãå½ä¸ä¸ªæä½éè¦æ¥åå¤ä¸ªé误æ¶ï¼ä¾å¦ Promise.any()ï¼å½ä¼ éç»å®çæææ¿è¯ºé½è¢«æç»æ¶ï¼å°±ä¼æåºè¯¥é误ã
AggregateError æ¯ Error çåç±»ã
æé 彿°
AggregateError()-
å建ä¸ä¸ªæ°ç
AggregateError对象
å®ä¾å±æ§
ä»ç¶ç±» Error ä¸ç»§æ¿å®ä¾å±æ§ã
以ä¸å±æ§å¨ AggregateError.prototype ä¸å®ä¹ï¼å¹¶ç±ææ AggregateError å®ä¾å
±äº«ã
AggregateError.prototype.constructor-
å建å®ä¾å¯¹è±¡çæé 彿°ã对äº
AggregateErrorå®ä¾æ¥è¯´ï¼åå§å¼ä¸ºAggregateErroræé 彿°ã AggregateError.prototype.name-
代表äºé误类åçåç§°ï¼å¯¹äº
AggregateError.prototype.nameæ¥è¯´ï¼åå§å¼ä¸º"AggregateError"ã
è¿äºå±æ§æ¯æ¯ä¸ª AggregateError å®ä¾çèªæå±æ§ã
errors-
ä¸ä¸ªæ°ç»ï¼åºæ¬ä¸åæ äº
AggregateErrorå®ä¾åæ¶ä½¿ç¨çè¿ä»£å¨ï¼ä¾å¦ï¼å¦æAggregateErroræ¯ç¨AggregateError()æé 彿°å建çï¼åä½ä¸ºç¬¬ä¸ä¸ªåæ°ä¼ éç»æé 彿°çä»»ä½è¿ä»£å¨çæçæ°ç»ã
å®ä¾æ¹æ³
ä»ç¶ç±» Error ä¸ç»§æ¿å®ä¾æ¹æ³ã
示ä¾
>æè·ä¸ä¸ª 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" ]
});
å建ä¸ä¸ª 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" ]
}
è§è
| è§è |
|---|
| ECMAScript® 2027 Language Specification> # sec-aggregate-error-objects> |