title: spring rector throw Exception if NOT empty
body: <p>Similar to <a href="https://stackoverflow.com/questions/55501980/spring-reactor-how-to-throw-an-exception-when-publisher-emit-a-value">Spring Reactor: How to throw an exception when publisher emit a value?</a>  </p>
  
  <p>I have a finder method in my DAO <code>java findSomePojo</code>  which returns result SomePojo . The finder calls amazon db apis and the <code>javasoftware.amazon.awssdk.services.dynamodb.model.GetItemResponse</code> has output of call.
  So I am trying this hasElement() check in my service layer  createSomePojo method. (Not sure if I am using it correctly- Iwas trying and debugging) </p>
  
  <p>Basically :
  I  want to check if there is already element, it is illegal to save and I would not call DAOs save. So I need to throw exception. </p>
  
  <p>Assuming that there is already a record  of SomePojo in DB, I try to invoke create_SomePjo of service .But I see  in logs that filter is not working and is get NPE when reactor invokes createModel_SomePojo making me believe that somehow even after check filter it throws NPE</p>
  
  <pre class="lang-java prettyprint-override"><code>///service SomePjoService it has create_SomePojo, find_SomePojo etc
  
  Mono&lt;Void&gt;  create_SomePojo(reqPojo){
  
  // Before calling DAO 's save I call serivice find (which basically calls DAOs find (Shown befow after this methid)
         Mono&lt;Boolean&gt; monoPresent = find_SomePojo(accountId, contentIdExtn)
                   .filter(i -&gt; i.getId() != null)
                   .hasElement();
         System.out.println("monoPresent="+monoPresent.toString());
         if(monoPresent.toString().equals("MonoHasElement")){
         //*************it comes here i see that***********//
             System.out.println("hrereee monoPresent="+monoPresent);
            // Mono&lt;Error&gt; monoCheck=
                  return  monoPresent.handle((next, sink) -&gt; sink.error(new SomeException(ITEM_ALREADY_EXISTS))).then();
         } else {
             return SomePojoRepo.save(reqPojo).then();
         }
  
  }
  
  Mono&lt;SomePojo&gt; find_SomePojo(id){
      return SomePojoRepo.find(id);
  }
  
  ==============================================================
  
  ///DAO : SomePojoRepo.java : it has save,find,delete
  Mono&lt;SomePojo&gt; find( String id) {
      Mono&lt;SomePojo&gt; fallback = Mono.empty();
      Mono&lt;GetItemResponse&gt; monoFilteredResponse = monoFuture
          .filter(getItemResponse -&gt; getItemResponse.item().size() &gt; 0&amp;&amp; getItemResponse!=null);
      Mono&lt;SomePojo&gt; result = monoFilteredResponse
          .map(getItemResponse -&gt; createModel_SomePojo(getItemResponse.item()));
  
      Mono&lt;SomePojo&gt; deferedResult = Mono.defer(() -&gt; result.switchIfEmpty(fallback));
          return deferedResult;
  }
  </code></pre>
  
  <p>I see there is hasElement() method on Mono . Not sure how to correctly use it. 
  I can achieve exception  if I call DAO save in my service create_SomePojo(reqPojo) directly without doing all this findner check because primary key constraint  will take care  and throw excpetion and I cna rethrow and then catch in service but what If I want to check in service and throw exception  with error codes . The idea is not to pass response error object to dao layer .</p>