Paolo
Paolo

Reputation: 2472

Where does Java language define if a Throwable is checked or not?

Both Exception and RuntimeException inherits from Throwable and do not implement any interface to tell whether they are checkd or not.

Where is it specified that Exception is checked and RuntimeException is unchecked? Is it hardwired in the language or the JVM?

Upvotes: 1

Views: 1311

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122414

It's defined in the Java Language Specification section 11.1.1.

Throwable and all its subclasses are, collectively, the exception classes.

Exception is the superclass of all the exceptions from which ordinary programs may wish to recover.

Error is the superclass of all the exceptions from which ordinary programs are not ordinarily expected to recover.

Error and all its subclasses are, collectively, the error classes.

[...]

The class RuntimeException is a direct subclass of Exception. RuntimeException is the superclass of all the exceptions which may be thrown for many reasons during expression evaluation, but from which recovery may still be possible.

RuntimeException and all its subclasses are, collectively, the run-time exception classes.

The unchecked exception classes are the run-time exception classes and the error classes.

The checked exception classes are all exception classes other than the unchecked exception classes. That is, the checked exception classes are all subclasses of Throwable other than RuntimeException and its subclasses and Error and its subclasses.

Upvotes: 8

Related Questions