ArithmeticException code example
Example 1: arithmetic exception
It occurs when there is an error
in the aritchmatic logic. For
Example we can't divide int to 0.
In this case it will throw arithmatic
exception and we can handle with
try catch block.(unchecked exception)
Example 2: arithmetic exception in java
class Example1
{
public static void main(String args[])
{
try{
int num1=30, num2=0;
int output=num1/num2;
System.out.println ("Result: "+output);
}
catch(ArithmeticException e){
System.out.println ("You Shouldn't divide a number by zero");
}
}
}