我有以下代码:
try {
...
try {
// This is *never* called
alert('TRY');
} catch (e) {
// But this *is* called
alert('CATCH');
}
} catch (e2) {
...
}
问题是,来自内部catch
块的警报被执行,而不是来自内部块的警报try
。
这是否完全符合规范,或者有人知道这里发生了什么吗?
例如,异步代码的异常可以运行到另一个 catch 块的上下文中吗?
请注意,这是我放在那里的真实代码,内部try
/没有遗漏catch
!一些异步代码可能会在进入块之前运行。
这是取自在 PyQt 4.9.0 和 Qt 4.8.0 中运行在 WebKit / QtWebKit 中的 Web 应用程序的代码。
好的,所以在内部 try/catch (第一个省略号所在的位置)之前还有一些代码:
DoSomething(function () {
var updatePromises = [];
var p;
for (...) {
p = new Promise();
updatePromises.push(p);
// Run asynchronous code to fulfill promise.
// Calls are chained using an array and a "setTimeout()" mechanism.
tasks.chain(function (promise) { ... }, this, p);
}
(function () {
...
}).future().apply(this, updatePromises);
}.bind(this));