What Makes an Exception Checked?
You'll learn the exact rule that determines whether an exception is checked or unchecked in Java's type hierarchy.
The Definition Rule
A checked exception is any class that:
- Extends
Exception(directly or indirectly), but - Does not extend
RuntimeException
This classification is purely about inheritance. The compiler treats these exceptions specially because they represent recoverable conditions that the calling code should be prepared to handle.
Why the Distinction Matters
Think of checked exceptions as predictable problems that a responsible caller should plan for — like a file not existing when you try to read it, or a network connection failing. The compiler enforces that you either:
- Handle them with a
catchblock, or - Declare them in your method signature with
throws
By contrast, RuntimeException and its subclasses are unchecked — the compiler doesn't force you to deal with them because they typically represent programming errors (like null pointer access) rather than external conditions.
The Hierarchy Picture
Throwable
├── Error (unchecked - don't catch)
└── Exception
├── IOException (checked - extends Exception)
├── SQLException (checked - extends Exception)
└── RuntimeException (unchecked)
├── NullPointerException (unchecked - extends RuntimeException)
└── IllegalArgumentException (unchecked - extends RuntimeException)
Anything under RuntimeException is unchecked. Anything under Exception but not under RuntimeException is checked.
Recoverable vs Programming Errors
Checked exceptions represent problems your code can reasonably recover from or inform the user about. They signal: "This might happen during normal operation — deal with it."
Key Takeaway: An exception is checked if it extends Exception but not RuntimeException, forcing compile-time handling for recoverable external conditions.