Any exception of type
can be handled by the user programs using the try-catch
block as explained in Exception Handling In Java with Example Program
class extends from
and any class which extends from
is considered as unchecked exception
. Any exception which extends from
class is considered as checked exception
. The difference is explained in Checked Exception Vs Unchecked Exception In Java
The other type of exceptions are
. These define exceptions that are not expected to be caught under normal circumstances by the user program. Exceptions of type
are used by the Java run-time system to indicate errors having to do with the run-time environment.
is an example of
. This is thrown when we recursively call the same method and it exceeds the number of method calls.
is also an
and this is thrown by the run-time system, when it does not have sufficient memory to execute the program.
The hierarchy of Throwable, Exception, RuntimeException and Error is shown below.