You must have got across AirthmeticException while performing arithmetic operations. Review the code snippet below:
public class CatchingArithmeticException {
public static void main(String[] args) {
int num=15;
int den=0;
//Integer Division
try {
System.out.println(num/den);
} catch( ArithmeticException e) {
System.out.println("Exception Occured :
Denominator should not be 0 incase of integer division");
}
//Modulo Division
int firOp=20;
int secOp=0;
try {
System.out.println(firOp%secOp);
} catch( ArithmeticException e) {
System.out.println("Exception Occured :
Second operand should not be 0 incase of modulo division");
}
}
}