title: exception handling and finally block in java
body: <pre><code>public class Confusion {
      Confusion(int i) {
          int j = 5;
          int[] a = new int[2];
          try {
              a[0] = 4;
              if (i &lt;= 0) {
                  int k = j / i;
              } else {
                  System.out.println(j / i);
              }
          } catch (ArithmeticException sa) {
              System.out.println("Wrong value" + sa);
          } catch (ArrayIndexOutOfBoundsException e) {
              System.out.println("out of range massage in Class");
          } finally {
              System.out.println("Executing finally block in code");
          }
      }
  
      void k() {
          int[] a = new int[2];
          {
              try {
                  a[4] = 4;
              } catch (ArrayIndexOutOfBoundsException e) {
                  System.out.println("out of range");
              }
          }
      }
  }
  
  public class Nested {
      public static void main(String[] args) {
          Confusion c = new Confusion(2);
          Confusion c1 = new Confusion(0);
          c1.k();
          c.k();
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>-2
  Executing finally block in code
  Wrong valuejava.lang.ArithmeticException: / by zero
  Executing finally block in code
  out of range
  out of range
  </code></pre>
  
  <p>Whenever i am executing the <code>finally{}</code> block written in the code below it is getting executed twice. Don't know why this is happening. I want to run the finally block only once.
  Is there any way to throw multiple exception in single method?</p>