Java Exception Types

Throwable, Error, Exception and RuntimeException are classes with special meaning in the Java language. The compiler imposes different constraints on these classes when used in throw statements and catch blocks. The classes have the following inheritance hierarchy:

Illustration of Exception Hierarchy

Throwable

In Java you can only throw and catch objects of type, or subtype of, Throwable.

The only Throwable subclasses provided by the Java API are Error and Exception.

Throwable is regarded as a checked exception.

Error

An Error is thrown to indicate a serious problem that the application should not try to resolve.

Error and all its subclasses are regarded as unchecked exceptions.

Example Errors

Exception

Exceptions are used for conditions that a reasonable application might want to catch.

Exception and all it's subclasses (except RuntimeException) are regarded as checked exceptions.

Example Exceptions

RuntimeException

The RuntimeException is a subclass of Exception. It is special because it is an unchecked exception.

RuntimeExceptions are used for conditions that an application typically don't catch, such as programming errors.

Example RuntimeExceptions

Comments

Be the first to comment!