// Program to use Multiple Catch Block with Exception.
class Exception05
{
public static void main(String args[ ])
{
try
{
int a = args.length;
System.out.println("a = " + a);
int b = 10 / a;
int c[ ] = { 1 };
c[10] = 100;
}
catch(ArithmeticException e)
{
System.out.println("Divide by 0: " + e);
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Array index oob: " + e);
}
System.out.println("After try/catch blocks.");
}
}
Output:case (1) if we don't pass any arguments in commandline
a = 0
Divide by 0: java.lang.ArithmeticException: / by zero
After try/catch blocks.
case (2) if we pass one arguments in commandline
a = 1
Array index oob: java.lang.ArrayIndexOutOfBoundsException: 10
After try/catch blocks.