Java – Exception Hierarchy

In this article, we will discuss exception hierarchy in detail with figure and explanation

Exception Hierarchy:

Throwable class is the root class for every exception and it branches out to 2 main categories i.e.;

  1. Exception
  2. Error

1. java.lang.Throwable:

  • Throwable is the root class for exception & it’s sub-type and error & it’s sub-types
  • In other words, it is super class for exception & error
  • java.lang.Throwable class extends java.lang.Object class (as shown in the above figure)
  • It defines 2 sub classes i.e.; Exception and Error

2. java.lang.Exception:

  • java.lang.Exception is super class for all types of Exception
  • It extends java.lang.Throwable class
  • Exception are due to programmatic logic
  • And it is recoverable
  • Exception are categorized into checked exception and unchecked exception
  • Example: RuntimeException, SQLException, IOException, FileNotFoundException, ArithmeticException, NullPointerException

3. java.lang.Error:

  • java.lang.Error is super class for all types of Error
  • It extends java.lang.Throwable class
  • Error are due to lack of system resources
  • And it is non-recoverable
  • All error fall into unchecked exception category, as it is raised due to lack of system resources at runtime
  • It is out of programming scope as such type of error can’t predicted, may be well planned care can be taken to avoid these kind of Error
  • Example: VirtualMachineError, AssertionError, ExceptionInInitializerError, StackOverflowError, OutOfMemoryError, LinkageError, InstantiationError

Note: above mentioned Exception and Error are again categorized into checked and unchecked exceptions

Related Articles:

References:

Happy Coding !!
Happy Learning !!

Java - Checked Exception v/s Unchecked Exception
Java - Runtime mechanism, what happens when exception is thrown ?