title: Java 8 Supplier Exception handling with CompletableFuture
body: <p>Consider the following code</p>
  
  <pre><code>public class TestCompletableFuture {
  
      BiConsumer&lt;Integer, Throwable&gt; biConsumer = (x,y) -&gt; {
          System.out.println(x);
          System.out.println(y);
      };
  
      public static void main(String args[]) {
          TestCompletableFuture testF = new TestCompletableFuture();
          testF.start();      
      }
  
      public void start() {
          Supplier&lt;Integer&gt; numberSupplier = new Supplier&lt;Integer&gt;() {
              @Override
              public Integer get() {
                  return SupplyNumbers.sendNumbers();                     
              }
          };
          CompletableFuture&lt;Integer&gt; testFuture = CompletableFuture.supplyAsync(numberSupplier).whenComplete(biConsumer);         
      }       
  }
  
  class SupplyNumbers {
      public static Integer sendNumbers(){
          return 25; // just for working sake its not  correct.
      }
  }
  </code></pre>
  
  <p>The above thing works fine. However <code>sendNumbers</code> could also throw a checked exception in my case, like:</p>
  
  <pre><code>class SupplyNumbers {
      public static Integer sendNumbers() throws Exception {
          return 25; // just for working sake its not  correct.
      }
  }
  </code></pre>
  
  <p>Now I want to handle this exception as <code>y</code> in my <code>biConsumer</code>. This will help me in handling the result as well as exception (if any) inside a single function (<code>biConsumer</code>).</p>
  
  <p>Any ideas? Can I use <code>CompletableFuture.exceptionally(fn)</code> here or anything else?</p>