title: Throw the original (inner) exception within a function in CompletableFuture?
body: <p>I am new to Java, so I hope this is not trivial, but I really could not find what I am looking for.</p>
  
  <p>I have a function that throws Exception: </p>
  
  <pre><code>public String foo(String s) throws MyException {
      if ("a".equals(s)){
        return s;
      } else {
        throw new MyException("Oh no!");
      }
  }
  </code></pre>
  
  <p>When MyException is just:</p>
  
  <pre><code>class MyException extends Exception{
  
    String str1;
  
    MyException(String str2) {
      str1=str2;
    }
    public String toString(){
      return ("MyException Occurred: "+str1) ;
    }
  }
  </code></pre>
  
  <p>Now I have another method that calls foo inside CompletableFuture:</p>
  
  <pre><code>private CompletableFuture&lt;String&gt; test() throws Exception{
          return CompletableFuture.supplyAsync(() -&gt; foo("b"));
  }
  </code></pre>
  
  <p>But foo throws exception, so there is a compilation error here since the call for foo is unhandled exception.</p>
  
  <p>All I want is to throw the original(inner) exception. How can I do that?</p>