title: How to record exceptions masked by finally block's exceptions in Java?
body: <p><em>Just a note</em>:
  I <strong>know</strong> that in Java <code>finally</code> block should never throw exceptions, otherwise it's [very, very, very] bad practice. <br/>
  I <strong>know</strong> that I should use <code>try-catch</code> inside <code>finally</code> to  handle (e.g. log or ignore) all exceptions and prevent them from propagating. <br/>
  I <strong>know</strong> that Java 7's Throwable has <code>getSuppressed</code> method, but I target Java 5 &amp; 6.</p>
  
  <p>Problem: In Java, in <code>try-finally</code> if an exception (name it <em>A</em>) is thrown by <code>try</code> block, control reaches <code>finally</code> block (in case of no exception it reaches it also, but it's not interesting in this question). Then, if <code>finally</code> block throws an exception (name it <em>B</em>), exception <em>A</em> is suppressed, or masked/swallowed, and exception <em>B</em> is propagated to the caller.</p>
  
  <p>Question: Can i somehow detect the situation when one exception is suppressed by another and log/record the first one? <br/>
  ... I spent too much time reasoning why particular exception has been thrown and not knowing what has really happened.</p>
  
  <p>Rationale: Often problematic <code>try-finally</code> blocks are coded in a library (today it was Hibernate), so I'm not able to modify them.</p>
  
  <p>Solution constraints: As I noted at the beginning, possible solution should not relay on Java 7, but, on the other hand, does not need to be production grade (being such would be a bonus). AOP is an option here.</p>
  
  <p>(Please don't post <em>trivial</em> answers like "use Java 7 for development":)</p>