尝试catch块没有捕获嵌套回调

run*_*431 4 javascript

我试图了解如何在嵌套回调时使用try/catch.为什么这段代码没有抓住我的新错误?

function test(cb) {
  setTimeout(function() {
    throw new Error("timeout Error");
  }, 2000);
}

try {
  test(function(e) {
    console.log(e);
  });
} catch (e) {
  console.log(e);
}
Run Code Online (Sandbox Code Playgroud)

Joe*_*rdi 8

当函数传递给setTimeout运行时,错误异步发生.抛出错误时,该test函数已经完成执行.