title: How to use CompletableFuture and CompletionStage with exception handling
body: <p>I am dealing with some code involving multiple blocking I/O operations to be performed in sequence. The context is a JVM based web application running on Java 8 and Tomcat. I have code that performs three operations in sequence. All are of the blocking nature, and the output of each operation may be utilized in a subsequent operation. Each operation can throw exceptions, either checked or unchecked. I have illustrated with some sample exceptions that can be thrown:</p>
  
  <pre><code>String output1 = callToRestAPI(); // throws MalformedUrlException, ConcurrentModificationException
  
  callToDatabase(output1); // throws SQLException, ConcurrentModificationException
  
  boolean output2 = callToSendEmail(output1); // throws MessagingException
  </code></pre>
  
  <p>How would I write this using Java 8's promising (no pun intended) CompletionStage and CompletableFuture?</p>