//program on exception handling using multiple catch
import java.util.Scanner;
class err4
{
public static void main(String[] args) { int a[]={12,13,14,15,23,44};
int i,b,c,d;
try
{
Scanner s=new Scanner(System.in);
System.out.print("Enter the two number:");
c=s.nextInt();
d=s.nextInt();
b=c/d;
System.out.println("content of array element are as
follows:");
for (i=0;i<7;i++ )
{
System.out.println(a[i]);
}
}
catch(ArithmeticException e)
{
System.out.println("Division by 0 Error."); System.out.println("Type of error:"+e);
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Array overflow.");
System.out.println("Type of error:"+e);
}
finally
{
System.out.println("I am always there.");
}
}
}
Output:-
0 Comments