Re: [Q] Handling exceptions?

21 views
Skip to first unread message

Stuart Knightley

unread,
May 2, 2013, 1:29:44 AM5/2/13
to q-con...@googlegroups.com
When you attach .done() directly to the rejected promise there is nothing handling the error in between and so it is thrown. Instead you add .done() after the handler, like so: http://jsfiddle.net/WJe84/1/ (although the variable is unnecessary, and you can just chain .done() at the end of .fail())

Hope this helps.

Stuart

On Wednesday, May 1, 2013 at 9:24 PM, Chris Vincent wrote:

I'm having trouble understanding how to handle an exception such that it doesn't get re-raised when I call done(). See here:

Am I missing something fundamental here?

--
You received this message because you are subscribed to the Google Groups "Q Continuum (JavaScript)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to q-continuum...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Domenic Denicola

unread,
May 2, 2013, 1:29:54 AM5/2/13
to q-con...@googlegroups.com

In short, yes. Promises never change their state. Instead, methods like `then` or `fail` return new promises, whose states are derived from the old ones. `rejectedPromise` will always be rejected, and the semantics of `.done()` is to throw when called on a rejected promise.

 

On the other hand, `var p = rejectedPromise.fail(function (err) { return true; })` will be a new promise, `p`, fulfilled with `true`. If you call `p.done()`, then the error will not be re-thrown.

Domenic Denicola

unread,
May 2, 2013, 1:30:13 AM5/2/13
to q-con...@googlegroups.com

Hah, beat me by seconds!

Stuart Knightley

unread,
May 2, 2013, 1:31:14 AM5/2/13
to q-con...@googlegroups.com
I was going to reply to an earlier message, but you beat as I was typing!

Chris Vincent

unread,
May 2, 2013, 8:02:01 PM5/2/13
to q-con...@googlegroups.com
Ahh, I see! So basically I wasn't chaining it. The fail() method returns a new promise on which I can then call done(). This makes much more sense now, thank you, and thanks for the quick response!
Reply all
Reply to author
Forward
0 new messages