Skip to content

Multiple catch statements suggestion (or explain) #474

Open

Description

@xamado

Hey there,

This might be something of a personal taste or bad usage, but I have gotten used to using custom errors for handling business logic errors (that means, things that I predict can happen) and handle them properly. For this use, using catch statements with custom error classes is very tidy and clean.

The one thing that usually bites me though, is that you can't add a generic error handler and expect the other errors to bubble up, let me explain with a simple example:

when().then(function() {
// stuff
}).catch(SomeLogicalError, function(err) {
// handle it properly
....

// bubble up so the caller chain also knows something failed
throw err;
}).catch(function(err) {
// oops, an unhandled error happened, like a javascript typo, this definetly needs special handling

// do something drastic, like report, or exit, or send an email to wake everyone up
});

The problem with the above, is that the err that gets catched by the first catch statement, re-throws, and that re-throw will be catched by the one below. So I don't see any possible way to have a generic error handler in a chain that won't break other code.

Wouldn't it be possible to just like one and only one typed error handler is selected and called, only call the generic catch() if none of the previous catch statements caught it ?

Cheers

Activity

  1. henrify commented on Apr 25, 2016

    @henrify

    Wouldn't it be possible to just like one and only one typed error handler is selected and called, only call the generic catch() if none of the previous catch statements caught it ?

    That would/could brake all existing software relying on When in an extremely obscure, hard to pinpoint and high WTF per minute inducing way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions