Write a program to implement the concept of Exception Handling using predefined exception.

 

class test1
{
public static void main(String args[])
{
int a[]={5,5};
int x,y;
try
{
x=(a[1]+a[0])/(a[0]-a[1]);
}
catch(ArithmeticException e)
{
System.out.println("Divide by zero Error");
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Array Index Out Of Range");
}
y=((a[0]+a[1])/(a[0]+a[1]));
System.out.println("y "+y);
}
}

 

 

Output:
C:\>java test1
Divide by zero Error
y 1
C:\>