I use bluebird
as promise
library.
I have two patterns of exception handling, and can not decide, which one is the better.
This is my function which rejects a promise:
var someAsyncMethod = function () {
return new Promise(function (resolve, reject) {
reject(new MyUniqueException());
});
};
These are the two patterns of handling the exception:
1) callback
pattern
someAsyncMethod()
.then(function resolved(){
// ...
}, function rejected(exception) {
// handle exception here
})
.catch(function (err) {
// handle error here
});
2) catch
pattern
someAsyncMethod()
.then(function () {
// ...
})
.catch(MyUniqueException, function (exception) {
// handle exception here
})
.catch(function (err) {
// handle error here
});
Which one should I use? What are the caveats? Or am I absolutely wrong and should do it some other way?