How is Java's exception hierarchy organised, and what sits at the top of it?
Everything that can be thrown in Java is a Throwable, and it sits at the very top of the tree.
Below Throwable there are two branches. The branch Error is for serious problems that the program cannot reasonably deal with, such as running out of memory or the stack overflowing. The branch Exception is for the problems that a program can be expected to handle.
Below Exception there is one more split. Every subclass of RuntimeException is an unchecked exception, and they are the programming mistakes such as a null pointer, an index that is out of range, or a wrong type of argument. Every other subclass of Exception is a checked exception, and those are the things that happen outside your program, such as a file that cannot be read or a network call that fails.
Throwable
|-- Error (unchecked, do not catch these)
| |-- OutOfMemoryError
| |-- StackOverflowError
|
'-- Exception (checked unless it is a RuntimeException)
|-- RuntimeException (unchecked, programming mistakes)
| |-- NullPointerException
| |-- ArithmeticException
| |-- IllegalArgumentException
| |-- ClassCastException
|
'-- (everything else is checked)
|-- IOException
'-- SQLException
The next question in this topic looks at the difference between the three branches in terms of what you should catch.