-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Log exception from @ExceptionHandler at higher level than debug [SPR-14861] #19427
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
Comments
Ibrahim Ghazal commented To reproduce: @RestController
public class DemoController {
@RequestMapping("/")
public String root() throws Exception {
throw new Exception("Exception thrown from root()");
}
@ExceptionHandler
public String exceptionHandler(Exception ex) {
System.err.println("Handling exception");
throw new RuntimeException("Unexpected RuntimeException!");
}
} Only the first exception is logged. "Unexpected RuntimeException!" does not get logged:
|
Juergen Hoeller commented Indeed, debug level does not seem appropriate there since exception handler methods are not meant to throw exceptions of their own in the first place, so it is likely a mistake that needs to be noticed. I tend to use warn level for such scenarios (since it only affects per-request state, not application-wide state), so I'm considering that level for both the Servlet MVC and the Web Reactive case. |
Eric Deandrea commented Yes but they should be able to throw exceptions that are annotated with |
Phil Krasko commented Juergen - I just recently updated to Spring 4.3.4 and started seeing this specific warning spew out in the logs. In my use case I have a generic exception handler which acts as a catch-all across my APIs. I was forced to create another In the particular scenario the warning message is bogus and very misleading. "Failed to invoke Do you have any recommendations on how to handle this? FWIW i understand why the level was changed to WARNING. It seems like this might be a fairly common case for those using both spring web and spring security. Perhaps the alternative/enhancement would be to update the Idea... @DefaultExceptionHandler(ignores = { AccessDeniedException.class })
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public void handleGenericException(final Throwable ex) {
// everything falls in here except for ignored items
}
@ExceptionHandler(FooException.class)
public void handleFooException(final FooException ex) {
return;
} Spring framework would resolve exceptions as it does today. If the exception isn't handled it would check for the presence of a |
Juergen Hoeller commented Phil Krasko, have you seen #19473 (linked as related above)? We allow an incoming exception to get silently re-thrown now and just log a warning for any other exception coming out of an exception handler method. This is currently just in recent 5.0 snapshots but will be backported to |
Phil Krasko commented No, I didn't see that but it sums up exactly what I'm after. |
Uh oh!
There was an error while loading. Please reload this page.
Ibrahim Ghazal opened SPR-14861 and commented
If an
@ExceptionHandler
annotated method throws an exception, the exception is only logged at the Debug level (see:spring-framework/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java
Line 385 in 9ccffb6
Note that spring-web-reactive already logs it at the Error level (see:
spring-framework/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java
Line 241 in 9ccffb6
Affects: 4.3.3
Issue Links:
@ExceptionHandler
Referenced from: commits 7627c38, 7e80d2d
The text was updated successfully, but these errors were encountered: