@ExceptionHandler
Learn @ExceptionHandler (Exception Handling, Spring MVC) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Fresher Notes @ExceptionHandler marks a controller method that handles exceptions thrown by handler methods, so you can turn an exception into a response. Scope : declared inside a controller it applies only to that controller; declared in a @ControllerAdvice class it applies to all controllers. Arguments : the method can take the exception, HttpServletRequest , Model and similar, and can return a view, a body or a ResponseEntity .