Divide by Zero Java Example Program


Syntax

try{
	//Statements
}catch(Expression_type Variable_name){
	//Statements
}

Divide by Zero Example Program

public class DivideByZeroException {
    public static void main(String[] args) {
        try{
            int number = 100/0;
        }catch(Exception e){
            System.out.println("Caught Exception while trying to divide 100 by zero : "+e.toString());
        }
    }
}

Sample Output

Caught Exception while trying to divide 100 by zero : java.lang.ArithmeticException: / by zero