title: Spring Webflux - Proper way to throw checked custom exception (not RuntimeException)
body: <p>May I ask what is the proper way to throw checked custom exception in Spring webflux please?
  I would like to insist, it is about <strong>checked custom exception</strong>, like MyException.java, not something like RuntimeException, and it is about <strong>throwing</strong> exception, not handling exception.</p>
  <p>I tried the following :</p>
  <pre><code>@Controller
  @SpringBootApplication
  public class QuestionHowToThrowException {
  
      public static void main(String[] args) {
          SpringApplication.run(QuestionHowToThrowException.class);
      }
  
      @PostMapping(path = &quot;/question&quot;, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
      public Mono&lt;ResponseEntity&lt;QuestionResponse&gt;&gt; question(@RequestBody QuestionRequest questionRequest) {
          Mono&lt;FirstStep&gt; firstStepMono = WebClient.create().post().uri(&quot;http://firstWebService:8111/getFirstStep&quot;)
                  .body(questionRequest.getThing(), String.class).retrieve().bodyToMono(FirstStep.class);
          Mono&lt;SecondStep&gt; secondStepMono = firstStepMono.map(oneFirstStep -&gt; getSecondStepFromFirstStepAfterCheck(oneFirstStep));
          return secondStepMono.map(oneSecondStep -&gt; ResponseEntity.ok(new QuestionResponse(oneSecondStep.getSecondThing())));
      }
  
      private SecondStep getSecondStepFromFirstStepAfterCheck(FirstStep firstStep) throws MyException {
          if (firstStep.getThingNeedsToCheckCanThrowException().equals(&quot;exception&quot;)) {
              throw new MyException(&quot;exception&quot;);
          } else {
              return new SecondStep(firstStep.getThingNeedsToCheckCanThrowException() + &quot;good&quot;);
          }
      }
  
      public class QuestionRequest {
          private String thing;
          public String getThing() {
              return thing;
          }
      }
  
      public class QuestionResponse {
          private String response;
          public QuestionResponse(String response) {
              this.response = response;
          }
      }
  
      public class FirstStep {
          private String thingNeedsToCheckCanThrowException;
          public String getThingNeedsToCheckCanThrowException() {
              return thingNeedsToCheckCanThrowException;
          }
      }
  
      public class SecondStep {
          private String secondThing;
          public SecondStep(String secondThing) {
              this.secondThing = secondThing;
          }
          public String getSecondThing() {
              return secondThing;
          }
      }
  
  }
  
  </code></pre>
  <p>This is not possible, since there in an unhandled exception in getSecondStepFromFirstStepAfterCheck method.</p>
  <p>If I throw and propagate, private SecondStep getSecondStepFromFirstStepAfterCheck(FirstStep firstStep) throws MyException the lambda caller method is not happy.</p>
  <p>What is the cleanest and proper way to throw custom exception in webflux please?</p>
  <p>Thank you</p>