Types of Exceptions
1. Family Tree (beginner — memorize top!)
Throwable → Error (fatal, don't catch!) + Exception → Checked (compiler forces!) + Unchecked/Runtime (logic bugs!).
// CHECKED (file/missing — must try/throws! else COMPILE ERROR!)
IOException, FileNotFoundException, SQLException, ClassNotFoundException
// UNCHECKED (bugs — optional catch!)
ArithmeticException (10/0), NullPointerException (null.x),
ArrayIndexOutOfBounds (a[5] on len3), NumberFormatException ("abc"→int),
InputMismatchException (abc for nextInt())
// ERROR (fatal — NEVER catch!)
OutOfMemoryError, StackOverflowError, NoClassDefFoundError
4. Checked vs Unchecked (exam table!)
| Checked | Unchecked | |
|---|---|---|
| Example | IOException | NullPointer |
| Compiler? | forces try/throws! | no force! |
| Cause | outside (files, network) | bug (null, index!) |
5. Exam Points
- Tree + 4 examples each — 7 marks, very frequent.
- Catch order + checked-force — 5 marks, favourite traps.