how to handle properly multiple exception thrower objects
<p>I want to handle exceptions on higher level not in this method but I want to be sure that object a &amp; b closed properly.</p>

<p>close() method can also throw an exception.</p>

<p>Is this template the proper solution for this or there is a smarter/simpler solution?</p>

<pre><code>public void foo() throws Exception {
 A a = null;
 B b = null;
 try {
  a = new A();
  b = new B();
  ...
 } catch(Exception e) {
  throw e;
 }
 finally {
  Exception ex = null;
  try {
   if (a != null)
    a.close();
  } catch(Exception x){
    ex = x;
  }
  try {
   if (b != null)
    b.close();
  } catch(Exception x) {
   ex = x;
  }
  if (ex != null)
   throw ex;
 }
</code></pre>
