In the diagram below I present the hierarchy of most common Exceptions and Errors:
Object
|
|_ Throwable
|
|_ Error
| |
| |_ AssertionError
| |
| |_ LinkageError
| | |
| | |_ ExceptionInInitializerError
| | |
| | |_ NoClassDefFoundError
| | |
| |_ VirtualMachineError
| |
| |_ StackOverflowError
|
|_ Exception
|
|_ RuntimeException
|
|_ NullPointerException
|
|_ IllegalArgumentException
| |
| |_ NumberFormatException
|
|_ IndexOutOfBoundException
| |
| |_ ArrayIndexOutOfBoundException
|
|_ ClassCastException
|
|_ IllegalStateException
For SCJP purposes, one needs to recognize which of them are thrown by the virtual machine (JVM) and which should be thrown programmatically. Read below, to learn that (those Errors and Exceptions which are not so common are briefly described):
Thrown by JVM
NullPointerExceptionStackOverflowError– when stack overflow occurs because of too deep recursionArrayIndexOutOfBound– when a negative index or index that is greater or equal to the size of an array was used to get an element of that arrayClassCastExceptionExceptionInInitializerError– raised when an unexpected exception occured in a static initializer, i.e. exception occured during evaluation of a static initializer or the initializer for a static variableNoClassDefFoundError– when JVM orClassLoaderinstance tried to load in the definition of a class, and that definition wasn’t found
Thrown programatically
IllegalArgumentException– when a method was passed an illegal or inappropriate argumentNumberFormatException– when convertion of String to one of numeric type failedIllegalStateException– when a method was invoked at an illegal or inappropriate time (e.g. usingScannerthat has been closed)AssertionError– when assertion failed