Wednesday, 12 September 2012

Java program codes: catch divide-by-zero error


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:

Post a Comment