“可能”一词表明,在某些情况下,即使您自己发现了错误,也可能会在控制台中收到此警告。
那些情况是什么?
最佳答案
Unhandled rejections/exceptions don't really have a good agreed-on asynchronous correspondence. The problem is that it is impossible to predict the future and know if a rejected promise will eventually be handled.
The [approach that bluebird takes to solve this problem], is to call a registered handler if a rejection is unhandled by the start of a second turn. The default handler is to write the stack trace to
stderr
orconsole.error
in browsers. This is close to what happens with synchronous code - your code doesn't work as expected and you open console and see a stack trace. Nice.Of course this is not perfect, if your code for some reason needs to swoop in and attach error handler to some promise after the promise has been hanging around a while then you will see annoying messages.
因此,例如,这可能会警告未处理的错误,即使它会得到很好的处理:
var prom = Promise.reject("error");
setTimeout(function() {
prom.catch(function(err) {
console.log(err, "got handled");
});
}, 500);
关于javascript - 在什么情况下bluebird的 "Possibly unhandled Error"警告可能是错误的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24520401/