I've got a question about error handling in Spring.
There is @ExceptionHandler annotation for handling exceptions in controller. For example I need to handle invalid json and this will work:
@ExceptionHandler(HttpMessageNotReadableException.class)
public ResponseEntity<Object> handleError(HttpServletRequest req, Exception ex) {
//Method logic
}
But! In this case if we throw HttpMessageNotReadableException inside rest method, then @ExceptionHandler will catch it anyway. So the question is: How can I handle only these exceptions which are thrown before we actually get into rest method?