在什么情况下,bluebird的“可能未处理的错误"可能会警告是错的吗? [英] Under what circumstances might bluebird's "Possibly unhandled Error" warning be wrong?

查看:64
本文介绍了在什么情况下,bluebird的“可能未处理的错误"可能会警告是错的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能"一词表示在某些情况下,即使您自己发现错误,也可以在控制台中收到此警告.

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

那些情况是什么?

推荐答案

这很好在文档中解释了:

未处理的拒绝/例外并没有达成良好的共识 异步通信.问题是不可能 预测未来并知道被拒绝的诺言是否最终会成为现实 处理.

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.

[bluebird解决此问题所需的方法]是称 注册的处理程序,如果在开始时未处理拒绝 第二回合.默认处理程序是将堆栈跟踪写入 浏览器中的stderrconsole.error.这接近发生的情况 使用同步代码-您的代码无法正常工作,您 打开控制台,然后查看堆栈跟踪.很好.

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

这篇关于在什么情况下,bluebird的“可能未处理的错误"可能会警告是错的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆