spring-framework / org.springframework.web.servlet.mvc.method.annotation / ResponseEntityExceptionHandler

ResponseEntityExceptionHandler

abstract class ResponseEntityExceptionHandler

A convenient base class for ControllerAdvice classes that wish to provide centralized exception handling across all @RequestMapping methods through @ExceptionHandler methods.

This base class provides an @ExceptionHandler method for handling internal Spring MVC exceptions. This method returns a ResponseEntity for writing to the response with a HttpMessageConverter, in contrast to org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver which returns a org.springframework.web.servlet.ModelAndView.

If there is no need to write error content to the response body, or when using view resolution (e.g., via ContentNegotiatingViewResolver), then DefaultHandlerExceptionResolver is good enough.

Note that in order for an @ControllerAdvice sub-class to be detected, ExceptionHandlerExceptionResolver must be configured.

Author
Rossen Stoyanchev

Since
3.2

See Also
#handleException(Exception, WebRequest)org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver

Constructors

<init>

ResponseEntityExceptionHandler()

A convenient base class for ControllerAdvice classes that wish to provide centralized exception handling across all @RequestMapping methods through @ExceptionHandler methods.

This base class provides an @ExceptionHandler method for handling internal Spring MVC exceptions. This method returns a ResponseEntity for writing to the response with a HttpMessageConverter, in contrast to org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver which returns a org.springframework.web.servlet.ModelAndView.

If there is no need to write error content to the response body, or when using view resolution (e.g., via ContentNegotiatingViewResolver), then DefaultHandlerExceptionResolver is good enough.

Note that in order for an @ControllerAdvice sub-class to be detected, ExceptionHandlerExceptionResolver must be configured.

Properties

PAGE_NOT_FOUND_LOG_CATEGORY

static val PAGE_NOT_FOUND_LOG_CATEGORY: String

Log category to use when no mapped handler is found for a request.

Functions

handleException

fun handleException(ex: Exception, request: WebRequest): ResponseEntity<Any>

Provides handling for standard Spring MVC exceptions.