What is Exception?
The exception denotes an abnormal event or unexpected situations.
Exception-handling is needed to handle unexpected situations like:
- inability to find files
- problems in network connectivity
- running out of memory
- resource allocation errors
To handle the exception an exception-handler is created, which processes the exception.
Keywords Used in Exception handling:
- The try
- The catch
- The throw
- The throws
- The finally
class TryCatchWithFinally
{
public static void main(String s1[])
{
try
{
int i=100/0;
int x[]=new int[10];
System.out.println(i);
System.out.println(x[11]);
}
catch (ArithmeticException e)
{
System.out.println("Division by zero");
}
catch(ArrayIndexOutOfBoundsException e1)
{
System.out.println("Wrong Index used...Index doesn't exist");
}
finally
{
System.out.println("Executing Finally....");
}
System.out.println("Outside try-catch");
}
}
Recent Comments