Java Exceptions: Types, Hierarchy & Handling
Java Exceptions
Explore Java exceptions—understanding errors, exception types, and the hierarchy that shapes robust error handling.
An exception is an unexpected event that interrupts the normal flow of a program, often leading to abnormal termination.
An exception can arise from a variety of causes, including:
- Invalid user input
- Device failures
- Network interruptions
- Physical limitations (e.g., out‑of‑disk‑space)
- Code defects
- Attempting to open unavailable files
Java Exception Hierarchy
Below is a simplified diagram of Java’s exception hierarchy.

The root of this hierarchy is the Throwable class. It splits into two major branches: Error and Exception.
Errors
Errors represent irrecoverable conditions such as JVM out‑of‑memory, stack overflows, library incompatibilities, and infinite recursion. They are typically beyond the programmer’s control, and attempting to handle them is discouraged.
Exceptions
Exceptions are conditions that a program can catch and recover from. When an exception occurs, the JVM creates an exception object that encapsulates the name, description, and program state at the time of the event.
In the next tutorial we will cover how to handle these exceptions. For now, let’s examine the two main categories within the Exception branch.
Java Exception Types
The Exception branch divides into RuntimeException (unchecked) and IOException (checked). Understanding the difference is key to effective error handling.
1. RuntimeException
RuntimeException instances arise from programming mistakes and are not checked at compile time. Common examples include:
- Improper API usage –
IllegalArgumentException - Null pointer dereference –
NullPointerException - Array index out of bounds –
ArrayIndexOutOfBoundsException - Division by zero –
ArithmeticException
In short, if it’s a runtime exception, it’s often a sign of a coding error that should be fixed rather than caught.
2. IOException
IOException represents checked exceptions that the compiler forces the developer to handle. Typical scenarios include:
- Attempting to open a non‑existent file –
FileNotFoundException - Reading beyond the end of a file
Proper handling of these checked exceptions is essential for building resilient applications.
We will dive into exception handling techniques in the next tutorial.
Java
- Master Java Operators: Types, Syntax, & Practical Examples
- Mastering Java's super Keyword: Advanced Usage & Practical Examples
- Mastering Java Interfaces: Concepts, Implementation, and Best Practices
- Mastering Java Exception Handling: Try, Catch, Finally, Throw & Throws Explained
- Java throw vs throws: Mastering Exception Handling with Practical Examples
- Mastering Multi‑Exception Handling in Java
- Mastering Java Try‑with‑Resources: Automatic Resource Management Explained
- Java Annotations Explained: Types, Placement, and Practical Examples
- Understanding Java's throws Keyword: Examples & Best Practices
- Mastering Java Exceptions: Handling Unexpected Errors Gracefully