Table of Contents
What is Exception ?
An exception is an abnormal condition that arises in a code sequence .When an Exception occurs the normal flow of the program is disrupted and the program/Application terminates abnormally, which is not recommended, therefore, these exceptions are to be handled.
Types of Exception
- Compile Time Exception — Checked Exception
All exceptions other than Runtime Exceptions are known as Checked exceptions as the compiler checks them during compilation to see whether the programmer has handled them or not. If these exceptions are not handled/declared in the program, you will get compilation error.
- Run Time Exception — Unchecked Exception
These exceptions are not checked at compile-time so compiler does not check whether the programmer has handled them or not but it’s the responsibility of the programmer to handle these exceptions and provide a safe exit.
Java Exception Hierarchy
Every Exception in Java is the subtype of Exception class which in turn is the subclass of Throwable. And as we know everything in Java derived from Object class Throwable also derived from class Object. Exception and Error are two different classes that derived from Throwable. Errors represent a situation that doesn’t occur because of a Programming error but that might happen at the time of program execution and these are abnormal behavior which java program cannot handle and shouldn’t bother to handle.