Java Exception Hierarchy

In the previous tutorial we have learnt about the basics of java exceptions. In this tutorial we are looking one step forward i.e Different Types of Exception and Exception Hierarchy.

Types of Exceptions in Java :

[box]Java Exceptions are divided into 3 types – Checked Exceptions,Unchecked Exceptions and Errors.[/box]
In Java, there are multiple situations that can cause exception. These situations are divided into 4 different types –

SituationCause of Exception
Code ErrorExceptions occurred due to wrong or invalid data. If user try to access the array element greater than size or something divided by zero error then these exceptions are called as code errors or data errors.
Standard Method ExceptionExceptions may be thrown if we try to access the standard methods with invalid input parameter.
Own ExceptionUser may generate his/her own exceptions depending on situation and type of code.
Java ErrorsErrors occurred due to JVM

below are the different types of Exception in Java –

A. Checked exceptions :

  1. A checked exception is an exception which is error or a problem occurred because of code written by programmer
  2. Checked Exception cannot be neglected by the programmer.
  3. Suppose we are opening the file and file is not present then exception occurred during the compile time can be considered as checked exception.
  4. These exceptions cannot be ignored at the time of compilation.
  5. Class that extend throwable class except RuntimeException and Error is considered as Checked exception.

B. Runtime exceptions:

  1. Classes that extent RuntimeException class is called as Runtime Exception.
  2. Runtime exceptions are ignored at the time of compliation.

C. Errors :

  1. These are not exceptions but the problems that are beyond the control of the user or the programmer.
  2. For example, Stack overflow, Virtual Machine Memory,AssertionError

Exception Hierarchy :

Exception Hierarchy  Java Programming