Exception:
An Exception is an unwanted event that interrupts the normal flow of the program execution get terminated.Exception Handling:
If an Exception occurs , which has not been handled by programmer than program execution gets terminated and a system generated error message is shown to the user.Code:
class Exception1
{
public static void main(String[] args)
{
try
{
int arr[]=new int[7];
arr[10]=30/3;
System.out.println("last statement of try block");
}
catch(ArithmeticException e)
{
System.out.println("U should not divide no by zero");
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Accessing array element outside of the limit");
}
catch(Exception e)
{
System.out.println("other exception");
}
System.out.println("-----");
}
}
Result:
0 Comments