I have a function doSomething()
that returns a promise chain, utilizing the Q framework. The contents are similar to something like:
loadDataSet :
You can't throw exceptions inside then
as no one will able to catch it. Instead, create a new Q.defer
and call reject on it whenever there's an error
loadDataSet : function (params) {
var deferred = Q.defer()
Q.fcall(function() {
//Do Something
}).then(function(){
//Do Something Else
deferred.reject('error message')
}, deferred.reject)
return deferred.promise
}
then use it like this
loadDataSet().then(function (data) {
//ok, got data
}).catch(function (err) {
//error!
})