How to handle only those exceptions in controller which are thrown outside rest method in Spring?

时间:2017-06-20 12:31:53

标签: java spring rest spring-mvc exception-handling

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?

0 个答案:

没有答案