Why this matters
- The checked-versus-unchecked distinction decides whether the compiler forces a caller to deal with your failure, which is an API design decision rather than a technical one.
- Catching the wrong branch of the hierarchy turns a recoverable problem into a hidden one, or a fatal problem into a corrupted program that keeps running.
- Reading a stack trace correctly is the single highest-value debugging skill, and most people read it in the wrong direction.
The hierarchy
RuntimeException sits under Exception but escapes the checked rule — that single exception to the rule is what the whole checked/unchecked distinction rests on.
Throwableis the root. Only its subtypes may appear in athrowor acatch.Errorsignals a condition outside your program's control — the heap is exhausted, a stack overflowed, a class is missing. Do not catch these.Exceptionsignals an application-level problem. Everything here is fair game to handle.RuntimeException, a subclass ofException, is the unchecked branch. The compiler does not require handling it.- Every other
Exceptionsubclass is checked, and the compiler insists you either catch it or declare it.
Checked versus unchecked
The compiler's rule is purely structural: is the type a RuntimeException or an Error? If not, it
is checked.
| Aspect | Checked | Unchecked |
|---|---|---|
| Examples | IOException, SQLException, ClassNotFoundException | NullPointerException, IllegalArgumentException, IllegalStateException |
| Compiler requires handling | Yes — catch or declare | No |
| Signals | An expected external failure | A programming error, usually |
| Caller can recover | Often — retry, fall back, report | Rarely — the code needs fixing |
| Appears in the signature | Must, via throws | Optional, for documentation |
Examples
CheckedIOException, SQLException, ClassNotFoundExceptionUncheckedNullPointerException, IllegalArgumentException, IllegalStateExceptionCompiler requires handling
CheckedYes — catch or declareUncheckedNoSignals
CheckedAn expected external failureUncheckedA programming error, usuallyCaller can recover
CheckedOften — retry, fall back, reportUncheckedRarely — the code needs fixingAppears in the signature
CheckedMust, via throwsUncheckedOptional, for documentation
The intent is that checked means 'something outside went wrong' and unchecked means 'the code is wrong'.
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 5 sections
- Common exceptions and what they really mean
- Reading a stack trace
- Wrapping preserves the cause
- Throwing well
- Common misreadings
Test yourself
Answer these before moving on — recall is what makes it stick.