title: How to handle empty event in Spring reactor
body: <p>Well, this sounds counter-intuitive to what reactive programming is, but I am unable to comprehend a way to handle nulls/exceptions.</p>
  
  <pre><code>private static class Data {
      public Mono&lt;String&gt; first() {
          return Mono.just("first");
      }
      public Mono&lt;String&gt; second() {
          return Mono.just("second");
      }
  
      public Mono&lt;String&gt; empty() {
          return Mono.empty();
      }
  }
  </code></pre>
  
  <p>I understand that fundamentally unless a publisher publishes an event, a subscriber will not act. So a code like this would work.</p>
  
  <pre><code>Data data = new Data();
  data.first()
      .subscribe(string -&gt; Assertions.assertThat(string).isEqualTo("first"));
  </code></pre>
  
  <p>And if the first call returns empty, I can do this.</p>
  
  <pre><code>Data data = new Data();
  data.empty()
      .switchIfEmpty(data.second())
      .subscribe(string -&gt; Assertions.assertThat(string).isEqualTo("second"));
  </code></pre>
  
  <p>But how do I handle a case when both the calls return empty (typically this is an exception scenario that would need to be propagated to the user).</p>
  
  <pre><code>Data data = new Data();
  data.empty()
      .switchIfEmpty(data.empty())
      .handle((string, sink) -&gt; Objects.requireNonNull(string))
      .block();
  </code></pre>
  
  <p>The handle is not called in the above example since no event was published.</p>