Throwable as a type : Throwable « java.lang « Java by API






Throwable as a type

/*
 * Output:
 * 
 * a = 0
   got t: java.lang.ArithmeticException: / by zero
 *  
 */

public class MainClass {
  public static void main(String args[]) {
  try {
      int a = args.length;
      System.out.println("a = " + a);
      int b = 42 / a;
      int c[] = { 1 };
      c[42] = 99;
  } catch(Throwable t) {
      System.out.println("got t: " + t);
  }
  }
}

           
       








Related examples in the same category

1.Throwable: printStackTrace()