An exception is a run time error which can be programmatically handled and which does not result in abnormal program termination facility of exception handling.
Exception handling adds the feature robustness to the language.
In java runtime errors are represented in object form. There is a predefine class errors at the root of this class hierarchy is class name throwable this class describes functionality, common to all run time errors. Throwable has two sub class, first is exception an second is error.
Types of Exception:
There are mainly two types of exceptions: checked and unchecked where error is considered as unchecked exception. The sun microsystem says there are three types of exceptions:
1) Check Exception: -
- Checked Exception
- Unchecked Exception
Those are exceptions which are forced by the compiler either to be properly caught declared to be thrown.
2) Unchecked Exception: -
Those exceptions are which are not forced by the compiler to be caught or to be thrown unchecked exception either represents common logical error or those run time error which cannot be programmatically handled.
What is Exception Handling
The mechanism for handling exceptions are handled by try-catch-finally block.
Exception thrown during the program execution of the try block can be caught and handled by catch block. A finally block is guaranteed to be executed.
catch(<exception type1> exObj)
catch(<exception type2> exObj)