Monday 12 September 2011

catch divide-by-zero error

public class MainClass {
  public static void main(String args[]) {
    int d, a;

    try {
      d = 0;
      a = 42 / d;
      System.out.println("This will not be printed.");
    } catch (ArithmeticException e) { //
      System.out.println("Division by zero.");
    }
    System.out.println("After catch statement.");
  }
}

No comments: