Code:
class Test
{
public static void main( String args[] )
{
try
{
System.out.println(" Try Block ");
// int a = 10/0;
// System.out.println( "ram".charAt(4) );
// int[] a = new int[-1];
System.out.println( new int[]{1,2,3}[2] );
System.out.println( new int[]{1,2,3}[3] );
}
catch( ArithmeticException e )
{
System.out.println(" Catch Block AE ");
}
catch( StringIndexOutOfBoundsException e )
{
System.out.println(" Catch Block SIOOBE ");
}
catch( NegativeArraySizeException e )
{
System.out.println(" Catch Block NASE ");
}
catch( Exception e )
{
System.out.println(" Catch Block -Exception ");
}
}
}
Output:
class Test
{
public static void main( String args[] )
{
try
{
System.out.println(" Try Block ");
// int a = 10/0;
// System.out.println( "ram".charAt(4) );
// int[] a = new int[-1];
System.out.println( new int[]{1,2,3}[2] );
System.out.println( new int[]{1,2,3}[3] );
}
catch( ArithmeticException e )
{
System.out.println(" Catch Block AE ");
}
catch( StringIndexOutOfBoundsException e )
{
System.out.println(" Catch Block SIOOBE ");
}
catch( NegativeArraySizeException e )
{
System.out.println(" Catch Block NASE ");
}
catch( Exception e )
{
System.out.println(" Catch Block -Exception ");
}
}
}
Output: