title: CompletableFuture exception handling runAsync & thenRun
body: <p>Let's say I have this sample code and an exception is encountered inside <code>runAsync</code>. My question is would this exception prevent the <code>thenRun</code> from getting executed as <code>thenRun</code> runs in the same thread as the caller method of this code.</p>
  
  <pre><code>private void caller() {
      CompletableFuture.runAsync(() -&gt; {
            try {
                // some code
            } catch (Exception e) {
                throw new CustomException(errorMessage, e);
            }
           }, anInstanceOfTaskExecutor).thenRun(
           // thenRun code
       ));
  }
  </code></pre>
  
  <p>I already went through <a href="https://stackoverflow.com/questions/44409962/throwing-exception-from-completablefuture">this</a> thread and it explains how you can handle exceptions thrown from asynchronous blocks (i.e. by blocking and using <code>join</code>). I want to know if code inside <code>thenRun</code> block would be executed or not if <code>CompletableFuture</code> <code>completesExceptionally</code>.</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>I ran some code to test this:</p>
  
  <pre><code>CompletableFuture.runAsync(() -&gt; {
        List&lt;Integer&gt; integerList = new ArrayList&lt;&gt;();
        integerList.get(1);    // throws exception
      }).thenRun(() -&gt; {
        System.out.println("No exception occurred");
      });
  </code></pre>
  
  <p>It does not print anything and it means exception didn't 'propagate up to/reach' the caller method's thread from the asynchronous block. I understand the expected behavior here now but I have following questions:</p>
  
  <ol>
  <li>Why is it silently failing even though the CompletableFuture completesExceptionally? </li>
  <li>How does it work in the background?</li>
  <li>Is it because both these threads (caller's thread &amp; asynchronous thread) have their own stack space?</li>
  </ol>