Exception handling in Spring MVC is the set of mechanisms for catching errors that occur during request processing and converting them into consistent, controlled responses instead of leaking stack traces to clients.
Key Points: • Local @ExceptionHandler methods inside a controller handle errors specific to that controller's endpoints. • @ControllerAdvice combined with @ExceptionHandler centralizes error handling across every controller in the application, avoiding duplicated logic. • HandlerExceptionResolver is a lower-level interface for building fully custom exception resolution strategies when annotations aren't flexible enough. • ResponseEntityExceptionHandler is a convenient base class provided by Spring for building a global handler for common Spring MVC exceptions. • Consistent error response shapes (status code, message, timestamp) across all endpoints make APIs easier for clients to consume reliably.
Example: A global @ControllerAdvice class can catch MethodArgumentNotValidException from failed @Valid checks across every controller and return a uniform 400 response listing all field errors, instead of each controller reimplementing that logic separately.
Interview Tip: A concise interview answer is:
"I use local @ExceptionHandler methods for errors specific to one controller, and a @ControllerAdvice class for handling common exceptions consistently across the whole application. For more control over how Spring resolves exceptions I can drop down to a custom HandlerExceptionResolver, though annotations cover the vast majority of cases."