Understanding Java Exception Hierarchy
-
Jason Yang - 27 Nov, 2025
- Updated 04 Jan, 2026
- Views —
Java provides a predictable and powerful error-handling mechanism centered around the Throwable hierarchy. Understanding this system is essential not only for writing safer and cleaner code but also for building production-grade applications—especially in modern frameworks like Spring Boot.
This guide walks you through:
- The Java exception hierarchy
- Real-world handling of checked vs unchecked exceptions
- Best practices used in enterprise systems
- How to design custom exceptions the right way
- Practical Q&A from a senior developer’s perspective
Java Exception Hierarchy Overview
Throwable
├── Error
│ ├── VirtualMachineError
│ │ ├── StackOverflowError
│ │ ├── OutOfMemoryError
│ │ └── UnknownError
│ ├── IOError
│ ├── AssertionError
│ ├── LinkageError
│ │ └── NoClassDefFoundError
│ └── AnnotationFormatError
│
└── Exception
├── IOException
│ ├── FileNotFoundException
│ └── SocketException
│
├── RuntimeException
│ ├── ArithmeticException
│ ├── NullPointerException
│ ├── NumberFormatException
│ └── IndexOutOfBoundsException
│ ├── ArrayIndexOutOfBoundsException
│ └── StringIndexOutOfBoundsException
│
├── SQLException
└── ClassNotFoundException
1. The Root: Throwable
At the top of Java’s exception model is the Throwable class. It has two primary branches:
Error— JVM-level failures (not recoverable)Exception— Application-level issues (recoverable)
2. Error: Critical JVM/System-Level Failures
Error represents internal system failures that applications should not attempt to handle.
| Class | Description |
|---|---|
StackOverflowError | Infinite recursion or deeply nested calls |
OutOfMemoryError | JVM heap exhausted |
InternalError | JVM internal malfunction |
Do not catch
Errorin your application code.
Let the JVM handle it. Attempting recovery often causes more harm.
3. Exception: Recoverable Application-Level Issues
Exception represents problems that commonly occur during normal execution—many of which can be handled or recovered from.
Common subclasses
| Class | Description |
|---|---|
IOException | I/O failures such as file or network problems |
SQLException | Database access errors |
ClassNotFoundException | Class not found at runtime |
RuntimeException | Unchecked exceptions (usually programming errors) |
4. Checked vs Unchecked Exceptions
Java differentiates between checked and unchecked exceptions:
✔ Checked Exceptions
- The compiler forces handling (
throwsortry-catch) - Usually caused by unpredictable external factors
- File operations
- Network connections
- Database access
try {
BufferedReader reader = new BufferedReader(new FileReader("file.txt"));
} catch (IOException e) {
System.out.println("Unable to read the file.");
}
✔ Unchecked Exceptions (RuntimeException)
- Compiler does not require handling
- Typically caused by programming mistakes
- Null access
- Invalid indexing
- Invalid input
int[] arr = {1, 2, 3};
System.out.println(arr[5]); // ArrayIndexOutOfBoundsException
5. Common RuntimeException Types
| Exception | Description |
|---|---|
NullPointerException | Dereferencing a null reference |
ArithmeticException | Division by zero, etc. |
NumberFormatException | Invalid numeric string |
IndexOutOfBoundsException | Invalid index for arrays/lists |
Subclasses include:
ArrayIndexOutOfBoundsExceptionStringIndexOutOfBoundsException