-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nested promises not working #7
Comments
When you throw an exception inside a promise, you are causing the promise to resolve as a rejection. If you had a fail handler at the end of your chain, you would see the fail handler get called. Promises allow for fail handlers to be attached at any point (even after the promise has been resolved as a rejection or success), so even if you're missing a fail handler in this code, the promise will not leak the exception; it will consider the exception as causing the promise to resolve to a rejection, and will dutifully notify any fail handlers if they are attached in the future. If you want the exception to leak out of the promise wrappers, you need to call end(). If you do that, you will then allow the exception to break free, as it were, of the promise, and get caught by the domain error handler. |
thanks for explanation. Q.ninvoke(db, 'collection', 'users')
.then(function(collection) {
return Q.ninvoke(collection, 'findOne', {url: id})
.then(function(item) {
throw new Error('123');
});
})
.end(); ? |
I haven't tested the code, but that should cause your exception to escape the promises and leak out. It should then be able to be caught by your domain's error handler. |
cant get it working with nested promises:
this works:
but this don't:
any help appreciated..
The text was updated successfully, but these errors were encountered: