title: How to run code after a call to Sytem.exit(0) in a finally block
body: <p>I have three classes say alpha, beta, gamma and each of the three classes has a <code>main</code> method.</p>
  
  <p>Both alpha and beta classes have, inside their <code>main</code> method, a <code>try...catch...finally</code> block like:</p>
  
  <pre><code>public class alpha{
  
      public static void main(String[] args){
          try{
              Do something;
          }catch(Exception ex){
              ex.printStackTrace();
          }
          finally{
              System.exit(0);
          }
      }
  }
  
  
  public class beta{
  
      public static void main(String[] args){
          try{
              Do something;
           }catch(Exception ex){
              ex.printStackTrace();
          }
          finally{
              System.exit(0);
          }
      }
  }
  </code></pre>
  
  <p>Now in gamma class i call main methods of alpha and beta classes to run continuously like below</p>
  
  <pre><code>public gamma{
  
      public static void main(String[] args) {
          try {
              alpha.main(arg);
              beta.main(arg1);
          } catch (Exception e) {
              e.printStackTrace();
          }
  }
  </code></pre>
  
  <p>The problem is that the code <code>beta.main(arg1)</code> is never reached due to the <code>System.exit(0)</code> inside the alpha class's <code>finally</code> block.
  Since alpha and beta are standalone applications when they executed separately they should terminate the service at the end of program.
  So now this there any way to reach the <code>beta.main(arg1)</code> line without much changing the actual functionality of alpha and beta classes.</p>
  
  <p>Kindly let me know if you need further details.
  Thanks in advance...</p>