1

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?

Ashot Karakhanyan
  • 2,804
  • 3
  • 23
  • 28
Paolo
  • 2,461
  • 5
  • 31
  • 45
  • check this thread [Java: checked vs unchecked exception explanation][1] [1]: http://stackoverflow.com/questions/6115896/java-checked-vs-unchecked-exception-explanation – Amin Bahiraee Apr 06 '14 at 11:07
  • it is hardwired in the java language. the jvm is just a tool to keep check on those – vikeng21 Apr 06 '14 at 11:07
  • **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.** – Braj Apr 06 '14 at 11:08
  • @vikeng21 The JVM has nothing to do with the checking of exceptions. – Marko Topolnik Apr 06 '14 at 11:16

1 Answers1

7

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.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
  • 1
    The way it's written, it still leaves open whether `Throwable` itself is checked or not. – Marko Topolnik Apr 06 '14 at 11:16
  • @MarkoTopolnik `Throwable` is definitely not one of the "unchecked exception classes", so it must be checked as it is one of the "exception classes other than the unchecked exception classes" – Ian Roberts Apr 06 '14 at 11:19
  • Yes, you're right. Just the added explanation doesn't cover it. – Marko Topolnik Apr 06 '14 at 11:25
  • 2
    @MarkoTopolnik indeed. Once of those cases where the extra sentence added for clarification actually makes things less clear... – Ian Roberts Apr 06 '14 at 12:04