ArithmeticException
Codeaft.java
class Codeaft
{
    public static void main(String args[])
    {
        int n=515, d=0;
        int result=n/d;
        System.out.println("Division "+result);
    }
}
Output
codeaft@codeaft:~$ javac Codeaft.java
codeaft@codeaft:~$ java Codeaft Exception in thread "main" java.lang.ArithmeticException: / by zero at Codeaft.main(Codeaft.java:6) codeaft@codeaft:~$
Java program to handle the ArithmeticException
Codeaft.java
class Codeaft
{
    public static void main(String args[]) 
    {
        int n=515, d=0;
        try
        {
            int result=n/d;
        }
        catch(ArithmeticException e)
        {
            System.out.println("Can't divide by zero");
        }
    }
}
Output
codeaft@codeaft:~$ javac Codeaft.java
codeaft@codeaft:~$ java Codeaft Can't divide by zero codeaft@codeaft:~$
Comments and Reactions