Handling error in Promises
Jeremy Martin
jmar777 at gmail.com
Tue Jan 13 08:48:06 PST 2015
Awhile back I did my best to summarize some of the previous es-discuss
threads on a related GitHub thread:
https://github.com/iojs/io.js/issues/11#issuecomment-65971175
Please see the immediately following comment as well for some clarification
on how Bluebird surfaces unhandled rejections.
On Tue, Jan 13, 2015 at 11:27 AM, Jeff Morrison <lbljeffmo at gmail.com> wrote:
> You might try reading through some of the previous threads that talk
> about the trickiness of surfacing promise errors in the general case.
>
> Unfortunately these threads usually devolve into an endless thread of
> discussion and debate that become next to impossible to actually read
> through later without several hours of spare time and a bottle of
> whiskey... But here's a recent one that's not *too* long and kind of talks
> about a couple of ideas:
>
> https://esdiscuss.org/topic/async-await-improvements (long, but talks
> about a couple potential/proposed solutions)
>
> -Jeff
>
>
> On 1/13/15 7:44 AM, Marius Gundersen wrote:
>
> A `promise.done()` method that throws if it receives a rejected promise
> has been discussed, but the consensus seems to be that browsers instead
> should report on rejected unhandled promises that are garbage collected.
> This is already implemented in Firefox (at least in the DevTools edition),
> where the following code will end up with an error in the console:
>
> ```js
> var p = new Promise(function(){throw new Error("oh noes");})
> p = null;
> ```
>
> Since there is no way to handle the thrown error outside the promise (the
> exception is thrown after the function returns) there isn't any reason for
> the exception to travel up the stack. Either the exception must be handled
> as a rejected promise or it must be handled in something like
> `window.onerror`.
>
> Marius Gundersen
>
> On Tue, Jan 13, 2015 at 12:35 PM, Boopathi Rajaa <legend.raju at gmail.com>
> wrote:
>
>> ```
>> Promise
>> .resolve()
>> .then(function(){
>> throw new Error('asdf');
>> });
>> ```
>>
>> Bluebird: (errors thrown - Good)
>> http://jsbin.com/kahuzi/1/edit?html,js,console
>>
>> native ES6:(errors not thrown)
>> http://jsbin.com/qivobibowa/3/edit?html,js,console
>>
>> Shouldn't all Uncaught errors be thrown, instead of catching it inside
>> the promise only ? For example, If I use Promise within a promise, the
>> uncaught error in the inner Promise will never be exposed to the outside
>> world and there is no way to bubble it up to the outside blocks.
>>
>> `.catch(function(err) { throw err; }) `
>>
>> will also be caught and nothing would be thrown.
>>
>> - Boopathi
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
>
> _______________________________________________
> es-discuss mailing listes-discuss at mozilla.orghttps://mail.mozilla.org/listinfo/es-discuss
>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
--
Jeremy Martin
661.312.3853
http://devsmash.com
@jmar777
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150113/5d8f2e41/attachment.html>
More information about the es-discuss
mailing list