为什么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
相关产品推荐
相关产品推荐

