Exception is an event occurrence which disrupts the normal
flow of execution of instructions in a program. Java uses this to handle errors
and other exceptional events.
When an error occurs in a method, an object (exception
object) is created by the method which is handed over to the runtime system.
This process is called throwing an exception. The object contains the details
of the error, its type, etc. The runtime system after receiving the exception
tries to find an appropriate way to handle it. The runtime method searches the
call stack to find an appropriate method containing the code for handling the
exception. That block of code is called exception handler.
When the type of exception thrown by the runtime system matches
with the type of exception that can be handled by an exception handler in a
method, then the exception is passed on to the handler so that it can catch the
exception. If the runtime system does find any appropriate handler for the
exception, the runtime system and consequently the program terminates. Normally
we have three types of exceptions: checked exceptions, errors and runtime