Java - Catch ArithmeticException for divide by zero

Description

Catch ArithmeticException for divide by zero

Demo

public class FinallyBlockExcep 
 {
    public static void main(String args[])
    {       /* w w w  .  j  a v a  2  s  .c o m*/
            
        try
        {
    
        int result=25/0;
        System.out.println("Thr resultandt output is:"+result); //this line is not executed if exception has occured
    
         }
        catch(ArithmeticException aex)
        {
        System.out.println(aex.toString());
        System.out.println("Exception has occured::::"+aex);
        }
        finally
           
        {
            System.out.println("Finnaly block is alwys executed if exception has occured or not");
        }
    }
}

Related Topic