What is Exception ?
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.