title: Java unchecked exception thrown by lambda is not caught
body: <p>I have a function that takes two lambdas as a parameters. These functions throw a specific unchecked exception that I want the function to catch:</p>
  
  <pre><code>    /**
       *
       * @param insert function to insert the entity
       * @param fetch function to fetch the entity
       * @param &lt;T&gt; type of entity being inserted
       * @return
       */
      @Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_COMMITTED)
      public &lt;T&gt; T getOrInsertWithUniqueConstraints(Supplier&lt;Optional&lt;T&gt;&gt; fetch, Supplier&lt;T&gt; insert) {
          try {
              Optional&lt;T&gt; entity = fetch.get();
              T insertedEntity = entity.orElseGet(insert);
              return insertedEntity;
          }
          catch (Exception e){
              //I expect/want the exception to be caught here, 
              //but this code is never called when debugging
              Optional&lt;T&gt; entityAlreadyInserted = fetch.get();
              return entityAlreadyInserted.get();
          }
      }
  </code></pre>
  
  <p>Which is called in a function belonging to another transaction:</p>
  
  <pre><code>@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  ...
  try {
      Player persistedPlayer = insertOrGetUtil.getOrInsertWithUniqueConstraints(
          () -&gt; playerRepository.findOne(newPlayer.getUsername()),
          //this lambda throws the unchecked DataIntegrityViolationException
          () -&gt; playerRepository.save(newPlayer)
      );
  }
  catch (Exception e){
      //the exception is caught here for some reason...
  }
  </code></pre>
  
  <p>Am I misunderstanding how Java lambdas work? Also worth noting is the code is using Spring's <code>@Transactional</code> and <code>CrudRepository</code></p>