【发布时间】:2016-12-28 01:05:41
【问题描述】:
我正在尝试使用 typescript 学习 Promise,但我遇到了一些问题,了解导致这种 vscode 调试行为的原因。
这是一个例子:
// example 1
new Promise((resolve, reject) => {
reject("test1"); // debugger stops as on uncaught exception
})
.catch(
error => {
console.log(error);
}
);
// output: "test1"
,并且:
//example 2
new Promise((resolve, reject) => {
setTimeout(() => {
reject("test2"); // debugger never stops
});
})
.catch(
error => {
console.log(error);
}
);
// output: "test2"
正如您所见,调试器在一种情况下会在 promise 拒绝处停止,但在另一种情况下则不会。但在所有情况下都会捕获错误,并且不会出现未处理的异常。
是我使用的 vscode 特定行为还是 es6-promise 绑定?还是我做错了?有没有人遇到过同样的问题?
【问题讨论】:
-
看起来确实是调试器中的一个错误。或者它只是将
reject调用视为throws,默认情况下它可能会停止。
标签: typescript error-handling promise visual-studio-code es6-promise