You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为什么async函数中的throw语句会延迟执行?

关于Async函数中throw语句执行时机的疑问
  • Async函数会以某种方式推迟(调度)throw语句的立即执行,而像console.log这类普通语句则会立即执行。

以下是示例代码:

async function test() {
  console.log('before throw')
  throw 'error in test()'
}

test()
console.log('exit')

我原本预期test()会执行到结束,因此控制台不会打印'exit'。


内容的提问来源于stack exchange,提问作者Maksim Shamihulau

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 19:10:33