JAVA PROGRAM OF NESTED TRY STATEMENTS--

//example of nested try statements::
PROGRAM CODE--

import java.io.*;
class NestTry
{

public static void main(String ar[])
{

try
{
int a=ar.length;
//if no command line argument are present the below code generate exception
int b= 42/a;
System.out.println("a =  "+a);
try
{
if(a==1)
{
a=a/(a-a); //it throw an exception divide by zero
}
if(a==2)
{

int c[]={1,2};
c[10]=9; //generate an out-of-bounds-exception
}
}catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Array index out-of-bounds :"+ e);
}
}catch(ArithmeticException ae)
{

System.out.println("divide by zero :"+ae);
}

}
}


 OUTPUT OF ABOVE PROGRAM--


Comments