首页 新闻 会员 周边

nodejs: 发生异常时 catch 中的代码没有执行

0
悬赏园豆:30 [已解决问题] 解决于 2023-12-19 17:45

下面的 nodejs 代码在 buildExtension 或者 buildUI 方法执行过程中发生异常时,没有执行 catch 中代码,请问如何解决?

try {
    await Promise.allSettled([buildExtension(), buildUI()])
} catch (ex) {
    console.error(ex)
    process.exit(1)
}
dudu的主页 dudu | 高人七级 | 园豆:30948
提问于:2023-12-19 16:16
< >
分享
最佳答案
0

Promise.allSettled 改为 Promise.all 即可解决,参考资料 Better handling of rejections using Promise.allSettled()

  • Promise.all() will technically reject as soon as one of the functions passed in the array rejects.
  • Promise.allSettled() will never reject - instead it will wait for all functions passed in the array to either resolve or reject.
dudu | 高人七级 |园豆:30948 | 2023-12-19 17:45
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册