title: Exception handling in code layers in java
body: <p>I have two layers in my project say A &amp; B. Layer A functions throw set of exceptions Ae1, Ae2, Ae3. Layer B functions throw exceptions Be1, Be2,Be3, Be4. Layer B functions are called from different functions in Layer A. </p>
  
  <p>A function in layer A can throws more than one exception. Similarly in layer B.  </p>
  
  <p>Also, I have a mapping like whenever I get exceptions Be1 and Be2 from Layer B functions, I <strong>catch</strong> those exceptions inside layer A function definition using try catch and throw it as Ae3. Similarly, exceptions Be3 is thrown as Ae2, and Be4 is thrown as Ae1. </p>
  
  <pre><code>public void function1InLayerB throws Be1, Be2, Be4{
      ......
  }
  </code></pre>
  
  <p>Now what I am doing is :</p>
  
  <pre><code>public void function1InLayerA throws Ae3, Ae1{
      try{
           function1InLayerB();
      } catch(Be1){
           throw new Ae3;
      } catch(Be2){
           throw new Ae3;
      } catch(Be4){
           throw new Ae1;
      }   
  }
  </code></pre>
  
  <p>So, I want to <strong>avoid such a lot of try catch blocks</strong>, by using a function  or any other different approach and have function in layer A simple as </p>
  
  <pre><code>public void fnuction1InLayerA throws Ae1, A2{
     ....
     new_function(function1InLayerB());
  }
  </code></pre>
  
  <p>Is it possible to write a common function like this ? </p>
  
  <p>Note : Java version 6.</p>