Override spring @ExceptionHandler methods
If I have a Spring controller with two SEPARATE methods, one of which is annotated:
@ExceptionHandler(Exception.class)
and the other is annotated:
@ExceptionHandler(SubException.class)
And my controller is throwing SubException.class
, is it handled by both methods or just @ExceptionHandler(SubException.class)
?
+3
source to share
3 answers
One handler will be called based on the best match.
The exact implementation is in AnnotationMethodHandlerExceptionResolver.findBestExceptionHandlerMethod(Object,Exception)
+4
source to share