Last active
December 12, 2015 03:38
-
-
Save bytespider/4708601 to your computer and use it in GitHub Desktop.
I would expect the exception to bubble up to `promise`'s error handler, or am I wrong?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Q = require('q'); | |
var step1 = Q.promise(function (resolve, reject) { reject('an error on 1'); }); // <-- reject here | |
var step2 = Q.promise(function (resolve, reject) { resolve(2); }); | |
var step3 = Q.promise(function (resolve, reject) { resolve(3); }); | |
var step4 = Q.promise(function (resolve, reject) { resolve(4); }); | |
step1.then(function (value) { | |
console.log(value); | |
return step2; | |
}).then(function (value) { | |
console.log(value); | |
return step3; | |
}).then(function (value) { | |
console.log(value); | |
return step4; | |
}).then(function (value) { | |
console.log(value); | |
}).fail(function (reason) { | |
console.log(reason); // <-- caught here | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Q = require('q'); | |
var promise = Q.promise(function (resolve, reject) { | |
setTimeout(function () { | |
resolve("a nice value"); | |
}, 3000); | |
}); | |
promise.then(function (value) { | |
console.log(value); | |
Q.fcall(function() { | |
throw new Error("An error"); // <-- error gets thrown here | |
}); | |
}, function (reason) { | |
console.log('Error', reason); // <-- error gets caught here | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment