title: JDK 1.7 Throwable `addSuppressed()` method
body: <p>Well, I get through related questions, I read the source code of JDK 1.7, but I don't find the answer.</p>
  
  <p>In this question I want to completely ignore <code>fillInStackTrace</code>.</p>
  
  <p>As of JDK 1.4 <code>initCause()</code> method was added. For example, when you use core reflection to invoke the method you receives InvocationTargetException with the cause that have target exception in it.</p>
  
  <p>When I saw this feature I started to use it also in a scenario like this</p>
  
  <pre><code>    try {
          //contains some code that can throw new IOException();
      }
      catch(IOException e){
          throw new RuntimeException(e);
      }
  </code></pre>
  
  <p>So, I catch an exception, I am not ready to deal with it here and I rethrow new exception where I have original exception as the cause. In some scenarious not RuntimeException, but my custom exception is used, so sometimes I also call to <code>e.getCause()</code> in order to properly handle this exception in the outer block.</p>
  
  <p>This is situation in pre JDK 1.7. Why and when should I use <code>addSuppressed()</code>? Should I change the code above to</p>
  
  <pre><code>    try {
          //contains some code that can throw new IOException();
      }
      catch(IOException e){
          RuntimeException re= new RuntimeException(e.getMessage());
          re.addSuppressed(e);
          throw re;
      }
  </code></pre>
  
  <p>And as a bonus question why doesn't <code>addSuppressed()</code> return <code>Throwable</code> as <code>initCause()</code> does to allow <code>throw (RuntimeException)new RuntimeException().initCause(e);</code>?  For example why can't I do?:</p>
  
  <pre><code>    try {
          //contains some code that can throw new IOException();
      }
      catch(IOException e){
          throw (RuntimeException)new RuntimeException(e.getMessage()).addSuppressed(e);
      }
  </code></pre>
  
  <p><strong>I extracted the answer to a separate post.</strong></p>