Exception Hierarchy in Java

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

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

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

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

Read Checked Exception v/s Unchecked Exception

 

References:

 

Read Also:

 

Happy Coding !!
Happy Learning !!

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