You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
// 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
The text was updated successfully, but these errors were encountered:
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.
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
The text was updated successfully, but these errors were encountered: