ArithmeticException In Java Example
Chapter:
Exception Handling
Last Updated:
19-04-2016 14:13:25 UTC
Program:
/* ............... START ............... */
public class JavaArithmeticException {
public static void main(String args[]) {
try {
int number1 = 30, number2 = 0;
int output = number1 / number2;
System.out.println("Result = " + output);
} catch (ArithmeticException e) {
System.out.println("Arithmetic Exception: You can't divide an integer by 0");
}
}
}
/* ............... END ............... */
Output
Arithmetic Exception: You can't divide an integer by 0
Notes:
-
ArithmeticException occurs when an integer is divided by zero.
Tags
ArithmeticException, Java, Exception