Defining global default exception handling advice for all other exceptions

If you want to create a generic exception message for all exceptions, we can add a method to RestResponseEntityExceptionHandler with the @ExceptionHandler(Exception.class) annotation.

The following code snippet shows how we can do this:

@ExceptionHandler(Exception.class)
public final ResponseEntity<ExceptionResponse> todoNotFound(Exception ex) {
//Customize and return the response
}

Any exception for which a custom exception handler is not defined will be handled by the previous method.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset