What is the difference between checked and unchecked exceptions? Which class should a custom exception extend?
Short answer
A checked exception (like IOException) must be caught or declared with throws, or the code won't compile. Unchecked ones (RuntimeException and subclasses) are not forced.
3 points to say:
- Business errors usually extend
RuntimeException. - When wrapping an error, always keep the original (
cause). - Don't catch an
Errorlike running out of memory.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.