javascript - 在什么情况下bluebird的 "Possibly unhandled Error"警告可能是错误的?

标签 javascript bluebird

“可能”一词表明,在某些情况下,即使您自己发现了错误,也可能会在控制台中收到此警告。

那些情况是什么?

最佳答案

这很好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.

因此,例如,这可能会警告未处理的错误,即使它会得到很好的处理:

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/

相关文章:

node.js - Mongoose 升级后,异步不会在回调中返回数据

javascript - promise 的 Node 链和代码可读性

javascript - Angular 有没有办法将字符串数组转换为修改后的字符串数组?

javascript - 根据背景颜色更改多个元素颜色

javascript - 如何禁用页面中的每次点击,仅在输入文本中自动对焦?

javascript - 使用 BlueBird.Promisify 时,未捕获的 typeError 中间值不是函数

javascript - bluebird - 函数返回 promise 对象而不是实际数据

node.js - 对另一个sequelize 查询的每个结果运行Sequelize 原始查询

javascript - 根据内容改变父div的宽度

javascript - Zone.js 中的自定义错误处理程序