Friday, January 4, 2013

Simple Try Catch

Source:

public class TryCatch {
   public static void main(String[] args) {
      try {
         int x = 1 / 0;
      } catch (Exception e) {
         System.out.println("Exception caught: " + e);
      }
   }
} 

Output:
   # java TryCatch
   Exception caught: java.lang.ArithmeticException: / by zero