【问题标题】:Async/ await to execute multiple functions with error handlingAsync/await 通过错误处理执行多个功能
【发布时间】:2020-11-22 02:01:14
【问题描述】:

我有 12 个异步函数,所有函数都应该一个接一个地执行,如果有错误就抛出。

async function fun1(){
...
}

async function fun2(){
...
}
async function fun3(){
...
}

async function executeAll() {
try{
  await fun1();
  await fun2();
  await fun3();
  } catch(e){
console.error(e)
}
}

它没有返回任何错误。有没有办法用 try/catch 处理个别错误。职能 ?或任何其他。

【问题讨论】:

  • 问题不清楚。这些函数中的一个实际上是否会引发错误并且您看不到它?

标签: node.js async-await try-catch


【解决方案1】:

我认为是。你也可以在 Promise 中捕获错误

     executeAll.then((result)=>{
          //some code
     }).catch((err)=>{
         //handling error
     })

【讨论】:

    猜你喜欢
    • 2016-08-04
    • 2020-08-16
    • 2018-09-03
    • 1970-01-01
    • 1970-01-01
    • 2019-10-15
    • 2021-10-24
    • 2020-05-15
    • 1970-01-01
    相关资源
    最近更新 更多