title: How to catch all the exceptions in Spring boot 2 webflux with @ControllerAdvice
body: <p>My application is made by Spring Boot 2 webflux and thymeleaf, I want to catch all the exception and render the error to a customized error page.</p>
  
  <p>I use @ControllerAdvice and  @ExceptionHandler to catch exceptions and handle errors in a central place, I can only handle all the exceptions which are thrown in my controller, but I cannot catch
   those mapping errors (content negotiation and HTTP mapping errors) such as UnsupportedMediaTypeStatusException.
  I searched and find this is a known issue (<a href="https://github.com/spring-projects/spri" rel="nofollow noreferrer">https://github.com/spring-projects/spri</a><code>enter code here</code>ng-framework/issues/21097#issuecomment-453468295). </p>
  
  <p>If I use WebMvc, there is no this kind of problem, all exceptions can be caught. My question is how to catch all the exceptions and show my own error page in webflux.</p>
  
  <p>Here is the brief code:</p>
  
  <pre><code>@ControllerAdvice
  @Slf4j
  public class DefaultExceptionHandlers {
      // works OK for my own thrown exception
      @ResponseStatus(HttpStatus.FORBIDDEN)
      @ExceptionHandler(value = CustomException1.class)
      public Mono&lt;String&gt; handleCustom1Exceptions(CustomException1 e) {
          return Mono.just("error1");
      }
  
      // works OK for my own thrown exception
      @ResponseStatus(HttpStatus.BAD_REQUEST)
      @ExceptionHandler(value = CustomException2.class)
      public Mono&lt;String&gt; handleCustom2Exceptions(CustomException2 e) {
          return Mono.just("error2);
      }
  
      // This exception handler is not called at all for the exceptions which are thrown by spring framework
      @ResponseStatus(HttpStatus.FORBIDDEN)
      @ExceptionHandler(value = Exception.class)
      public Mono&lt;String&gt; handleAllExceptions(Exception e) {
          return Mono.just("error3);
      }
  }
  </code></pre>