简体   繁体   English

Promise / bluebird.js中的错误处理

[英]Error handling in Promise / bluebird.js

Whats the difference between those then calls in context of handling errors ? 请告诉我那些之间的差异then在错误处理方面呼吁?

.then(functionThatReturnsPromise(arg))

.then(function() {
    return functionThatReturnsPromise(arg);
})

In first example, if function functionThatReturnsPromise throws error , catch block isnt called and bluebird prints error; 在第一个示例中,如果函数functionThatReturnsPromise抛出error ,则未调用catch块,并且bluebird打印错误;

Possibly unhandled Error: <msg>

The first one runs functionThatReturnPromise before the previous promise completes! 第一个在先前的承诺完成之前运行functionThatReturnPromise If you write 如果你写

blah()
.then( functionThatReturnsPromise(arg) )

its like writing 就像写作

var firstPromise = blah();
var x = functionThatReturnsPromise(arg)
firstPromise.then(x);

Additionally, then expects to be passed a callback function but you are passing it a promise object. 此外, then希望传递给回调函数,但您传递给它的是Promise对象。 Its no surprise that its not working correctly. 它不能正常工作也就不足为奇了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM