title: Java streams .orElseThrow
body: <p>I want convert a piece of code from a Connection Pool project i have been working on to use streams</p>
  
  <p>the original code is </p>
  
  <pre><code>for (Map.Entry&lt;JdbConnection,Instant&gt; entry : borrowed.entrySet()) {
    Instant leaseTime = entry.getValue();
    JdbConnection jdbConnection = entry.getKey();
    Duration timeElapsed = Duration.between(leaseTime, Instant.now());
    if (timeElapsed.toMillis() &gt; leaseTimeInMillis) {
      //expired, let's close it and remove it from the map
      jdbConnection.close();
      borrowed.remove(jdbConnection);
  
      //create a new one, mark it as borrowed and give it to the client
      JdbConnection newJdbConnection = factory.create();
      borrowed.put(newJdbConnection,Instant.now());
      return newJdbConnection;
    }
  }
  
  throw new ConnectionPoolException("No connections available");
  </code></pre>
  
  <p>I have got to the point of this</p>
  
  <pre><code>borrowed.entrySet().stream()
                     .filter(entry -&gt; Duration.between(entry.getValue(), Instant.now()).toMillis() &gt; leaseTimeInMillis)
                     .findFirst()
                     .ifPresent(entry -&gt; {
                       entry.getKey().close();
                       borrowed.remove(entry.getKey());
                     });
  
  
  JdbConnection newJdbConnection = factory.create();
  borrowed.put(newJdbConnection,Instant.now());
  return newJdbConnection;
  </code></pre>
  
  <p>The above can compile but the moment i add <code>orElseThrow</code> after <code>IfPresent</code> i am getting the following</p>
  
  <pre><code>/home/prakashs/connection_pool/src/main/java/com/spakai/ConnectionPool.java:83: error: void cannot be dereferenced
                         .orElseThrow(ConnectionPoolException::new);
  </code></pre>