最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Under what circumstances might bluebird's "Possibly unhandled Error" warning be wrong? -

programmeradmin2浏览0评论

The word "possibly" suggests there are some circumstances where you can get this warning in the console even if you catch the error yourself.

What are those circumstances?

The word "possibly" suggests there are some circumstances where you can get this warning in the console even if you catch the error yourself.

What are those circumstances?

Share Improve this question asked Jul 1, 2014 at 22:55 callumcallum 38.1k39 gold badges114 silver badges175 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

This is pretty well explained in the docs:

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 or console.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.

So, for example, this might warn of an unhandled error even though it will get handled pretty well:

var prom = Promise.reject("error");
setTimeout(function() {
    prom.catch(function(err) {
        console.log(err, "got handled");
    });
}, 500);
发布评论

评论列表(0)

  1. 暂无评论