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

The word "possibly" suggests there are some circumstances where you can get this warning in t

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);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745344028a4623461.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信