Skip to content

Exclude an exception from @ExceptionHandler [SPR-13932] #18504

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

Closed
spring-projects-issues opened this issue Feb 8, 2016 · 5 comments
Closed
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 8, 2016

Bill Chen opened SPR-13932 and commented

As seen in the referenced SO question, if one wants a blanket handler for all Exceptions apart from a few, one will have to rethrow the unhandled exception in the @ExceptionHandler method, which causes a horrendous ERROR to be logged.

Can some facility be provided to statically (via the annotation) or, even better, dynamically skip an exception in a handler?


Affects: 4.2.4

Reference URL: http://stackoverflow.com/q/35267756/499922

Issue Links:

Referenced from: commits cdfcc23, 6ef2d82

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

I've reduced the log level in ExceptionHandlerExceptionResolver to DEBUG. That probably resolves your issue. That said the idea of excluding an exception from @ExceptionHandler may be more generally useful since it allows other registered HandlerExceptionResolver's to get involved. Possibly an exclude flag on @ExceptionHandler in which case we might consider supporting it on the type level.

For anyone interested in the features please comment/vote.

@spring-projects-issues
Copy link
Collaborator Author

Martin Macko commented

Hi, I've tried to implement this feature. Could you possibly look at my code and do a review?

#972

Thanks.

@spring-projects-issues
Copy link
Collaborator Author

Bill Chen commented

@Rossen I think changing the log level is okay for my case as it removes any undesired side effects of rethrowing. However, the more generic case you mentioned is more useful I guess.

@rstoyanchev
Copy link
Contributor

Rather than an exclusion flag, it seems this could be done with two @ExceptionHandler methods, one for the more general exception and another for the more specific.

@rstoyanchev rstoyanchev added the status: declined A suggestion or change that we don't feel we should currently apply label Jan 29, 2019
@rstoyanchev rstoyanchev removed this from the 5.x Backlog milestone Jan 29, 2019
@yacota
Copy link

yacota commented Oct 10, 2019

Hi @rstoyanchev, I hope you don't mind If I explain our use case in this closed issue

We have a globalErrorHandler with @ExceptionHandler(value = {Exception.class, Error.class}) that is catching every error in order to track them and check code regressions after each deployment.

We also have business exceptions (RedirectExceptions) that we'd like to handle in a custom HandleInterceptor, in its afterCompletion method. As you know this does not work because the exception has already been handled by our globalErrorHandler because we can not make it ignore these kind of business exceptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants