Solution 1: the Controller-Level @ExceptionHandler
Solution 2: the HandlerExceptionResolver
Solution 3: @ControllerAdvice
This enables a mechanism that breaks away from the older MVC model and makes use of ResponseEntity along with the type safety and flexibility of @ExceptionHandler:
The@ControllerAdvice annotation allows us to consolidate our multiple, scattered @ExceptionHandlers from before into a single, global error handling component.
The actual mechanism is extremely simple but also very flexible:
It gives us full control over the body of the response as well as the status code.
It provides mapping of several exceptions to the same method, to be handled together.
It makes good use of the newer RESTful ResposeEntity response.
Solution 4: ResponseStatusException (Spring 5 and Above)
https://www.baeldung.com/exception-handling-for-rest-with-spring