The following code works fine without the exception, and if the there is exception in function bar, the program just finished without any output. I have checked Q's source code, it catches the exception and reject it. Spent some time but still don't know what's the proper way to get the exception info.
function foo(val) {
var deferred = Q.defer();
if (val) {
deferred.resolve(val);
} else {
deferred.reject(val);
}
return deferred.promise;
}
function bar() {
var deferred = Q.defer();
foo(true)
.then(function(res) {
throw new Error('true error!');
deferred.resolve(true);
}, function(err) {
throw new Error('false error!');
deferred.reject(false);
});
return deferred.promise;
}
bar()
.then(function(res) {
console.log('true');
}, function(err) {
console.log('false');
})
.done();