Change the Better World

Why @ExceptionHandler(Exception.class) would not catch handleMethodsArgumentNotValid? 본문

REST

Why @ExceptionHandler(Exception.class) would not catch handleMethodsArgumentNotValid?

white_cheetah 2022. 9. 30. 10:40

When a exceptionhandler is inherited from ResponseEntityExceptionHadler, we expect that @ExceptionHadler(Exception.class) is used to catch All exceptions.

But if MethodArgumentNotValidException is faced, our expectation misses our tip because the Exception wouldn't handle it.

This MethodArgumentNotValidException is used and handled with at ResponseEntityExceptionHadler so when an exception happened.

The MethodArgumentNotValidException or any kind of exception in ResponseEntityExceptionHadler is controlled by ResponseEntityExceptionHadler rather than the child exception which is inherited. If ResponseEntityExceptionHadler couldn't handle it, then @ExceptionHadler(Exception.class) will handle it.

'REST' 카테고리의 다른 글

How to control version?  (0) 2022.09.30
RESTful Web Service  (0) 2022.09.26
Comments