Skip to content
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

Multiple catch statements suggestion (or explain) #474

Open
xamado opened this issue Dec 1, 2015 · 1 comment
Open

Multiple catch statements suggestion (or explain) #474

xamado opened this issue Dec 1, 2015 · 1 comment

Comments

@xamado
Copy link

xamado commented Dec 1, 2015

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

@henrify
Copy link

henrify commented Apr 25, 2016

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants