Finally Exception in Java


Code that shows how finally will work in Exceptions.

File:fin.java

class fin
{
public static void main(String ar[])
{
int a[]={2,3};
try
{
a[2]=5;
System.out.println(“The Value is added to the index”);
}
catch(Exception e)
{
System.out.println(“Genereated Exception ” +e);
}
finally
{
System.out.println(“Please make sure the Syntax and declaration is correct”);
}
}
}

Output:
Genereated Exception java.lang.ArrayIndexOutOfBoundsException: 2
Please make sure the Syntax and declaration is correct

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s