I am trying to capture all exceptions of some class in my Controller class. It works fine when I define it like this:
@ExceptionHandler(NoSearchResultException.class) public String handleNoSearchResultException() { return "someView"; } But not if I add any parameters:
@ExceptionHandler(NoSearchResultException.class) public String handleNoSearchResultException(Exception e) { return "someView"; } What could possibly be happening? Also, I've read @ExceptionHandler does not support Model arguments, so how would I pass a parameter (like the error message for instance) to the view in order to offer a dynamic error page?
@ExceptionHandlerdoes support the Model but only as a return value NOT as an argument. So you can put whatever you like in there (you could even return aModelAndViewwith everything in it, instead of only a view name). More information about supported method argument types and return value types in the javadoc. Could you post your mvc configuration and which Spring version are you using.