onezhaoyn
12/25/2018 - 3:00 AM

async /await - 用try...catch 代码块包裹

async /await - 用try...catch 代码块包裹

// 如果await命令后的promise对象的运行结果可能是 rejected,最后把 await 命令放在 try...catch 代码块中:

async function myFunction () {
  try {
    await someThingThatReturnsAPromise()
  } catch (err) {
    console.log(err)
  }
}