Exception is exception and definition is same in all languages -
An exception is an abnormal condition that arises in a code sequence at run time.In other words,an exception is an event,which occurs during the execution of a program, that disrupts the normal flow of the program.When an exception is thrown,an object of a particular exception subtype is instantiated and handed to the exceptional handler as an argument to the catch clause.An actual catch clause as shown below-
try {
// some code here
}
catch (ArrayIndexOutOfBoundException e) {
e.printStackTrace();
}
In this example,e is an instance of the ArrayIndexOutOfBoundExceptionclass.As with any other object,we can call its methods.
In Jave we have these five keywords which are used in Exception handling:
- try
- catch
- finally
- throw
- throws