Mega Code Archive

 
Categories / Java Tutorial / Statement Control
 

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.");   } }