Test multiple try-catch statement in java ex2

Write a program to test multiple try-catch statement in java.

package Exception_demo;


public class multiplecatch_demo
{
    public static void main(String args[])
    {
        int a[]=new int[3];
        try
        {
            for(int i=1;i<=3;i++)
            {
                a[i]=i*i;
            }
            for(int i=0;i<3;i++)
            {
                a[i]=i/i;
            }
                       
                                        
        }
        catch(ArrayIndexOutOfBoundsException e)
        {
            System.out.println("Array index is out of bounds");
        }
        catch(ArithmeticException e)
        {
            System.out.println("Divide by zero error");
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *