title: try-catch block in Java - execution statements in catch code
body: <p>I have a question about the order of the execution of statements in a catch block in Java.
  when I run the following class Test1 (see below), I expect to have as output first Hi!, then the result of the e.printStackTrace(); statement, and then Bye!. However, I never get this order. Please, look at the outputs, which I have pasted below.</p>
  
  <pre><code>public class Test1 {
  
      public static void calculate() {
          try {
               int h = 5/0; 
          } catch (ArithmeticException e) {
              System.out.println("Hi!");
              e.printStackTrace();
          } 
          System.out.println("Bye!");
      }
  
      public static void main(String[] args) {
          calculate();
      }
  
  }
  </code></pre>
  
  <p>Output1:</p>
  
  <pre>
  Hi!
  Bye!
  java.lang.ArithmeticException: / by zero
      at Test1.calculate(Test1.java:6)
      at Test1.main(Test1.java:15)
  </pre>
  
  <p>Output2:</p>
  
  <pre>
  java.lang.ArithmeticException: / by zero
      at Test1.calculate(Test1.java:6)
      at Test1.main(Test1.java:15)
  Hi!
  Bye!
  </pre>
  
  <p>I have two questions: </p>
  
  <p>1.) The more important question: Why I always have Hi! and Bye! printed always one after the other, even though mye.printStackTrace() in the code is between them?</p>
  
  <p>2.) Why sometimes I have the output of the statement e.printStackTrace() before Hi!, and sometimes after Bye! ? I have run the program many times and I cannot understand under what circumstances I get one or the other print. </p>
  
  <p>Thank you.</p>
  
  <p>I am using Java 6, and Eclipse (Ganymed).</p>