Checked vs Unchecked Exceptions in Java: Key Differences & When to Use
Checked Exceptions are subclasses of Exception that Java forces you to either catch or declare; Unchecked Exceptions extend RuntimeException and the compiler never asks you to handle them.
Developers often lump all “exceptions” together because the IDE flags everything red at first. In the rush to clear errors, they suppress or bubble Checked ones, then wonder why production still crashes on NullPointer—an Unchecked silent bomb.
Key Differences
Checked: compiler-enforced, recoverable (IOException). Unchecked: optional handling, usually bugs (NullPointer). One demands a plan, the other screams “fix your code.”
Which One Should You Choose?
Expose Checked for expected external failures—file missing, network down. Throw Unchecked for programming mistakes—null argument, bad index. Let the caller decide how much control they need.
Examples and Daily Life
Think Checked like airline check-in: no boarding pass, no fly. Unchecked like forgetting your passport—plane leaves, but you’re stuck at security, cursing yourself.
Can I turn a Checked into Unchecked?
Yes, wrap it in RuntimeException, but you lose the safety net for callers.
Why doesn’t NullPointerException force handling?
It signals a code bug, not an external condition, so Java treats it as an Unchecked RuntimeException.