On Tue, Aug 6, 2013 at 1:02 PM, Allen Wirfs-Brock <al...@wirfs-brock.com>wrote:

> Has anybody ever actually seen a JS exception handler that really needs to
> take conditional action depending upon whether as TypeError or RangeError
> was thrown?
>

For what it's worth, as someone using both promises and custom error types
in the field, we do switch on different types of errors.  We alternate
between instanceof and testing the .name property on the exception as a
stylistic choice.

Here's a common idiom (note, I typed this from memory, and haven't compiled
it:

fetchServiceResult().then(function(result) {
    // use result
}).catch(function(error) {
    if (error instanceof NetworkError) {
        // perhaps retry a couple times
        // perhaps show a dialog box
    } else {
        throw error; // bubble anything else
    }
});
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to