Java Exception catch divide by zero exception

Description

Java Exception catch divide by zero exception

public class Main {
  public static void main(String[] args) {
    int d = 0, result;
    try {// ww  w  . ja  va 2 s  .c  o  m
      result = 100 / d;
    } catch (ArithmeticException e) {
      System.out.println("An arithmetic exception occurred.");
      result = 100;
    }
    System.out.println("After catch block");
  }
}



PreviousNext

Related