Exception Hierarchy
As we know that object class is the parent class of every class in java so Throwable class is the subclass of the Object class. The Throwable class is the superclass for all exceptions and errors in java.
Exception Class :
Exceptions are recoverable that occurs at runtime if encountered in a program we can handle such kind of situation.
For example:
ArithmeticException,ArrayIndexOutOfBoundsException,NullPointerException etc.The tree view hierarchy of Exception Class according to Java 8 API is given below. Exceptions are recoverable whereas errors are non-recoverable.
Demo Example:
The following program have ArithmeticException inside method m2. The catch block provides an alternative option for handling such type of condition.
Error Class :
Errors are non-recoverable that occur at runtime if encountered in program termination is the only option. we can't handle this kind of situation.
For example, OutOfMemoryError occurs when JVM runs out of memory, StackOverflowError occurs when stack overflows, etc.
The tree view hierarchy of Error class according to Java 8 API is given below.
Fig.2
Fig.3

Fig.4
