Why runtime exception is unchecked exception?

Priyank Doshi picture Priyank Doshi · Jul 18, 2012 · Viewed 7.5k times · Source

Generally if any class extends Exception , it becomes checked exception. Runtime exception also extends Exception. Then how is it unchecked exception?

Is it like they have a custom check in compiler for this special case?

EDIT : I have proper idea about checked v/s unchecked exception and their pros & cos etc. I don't accept differences between them in answer.

Answer

Jon Skeet picture Jon Skeet · Jul 18, 2012

It's explicitly in the specification, section 11.1.1:

RuntimeException and all its subclasses are, collectively, the runtime exception classes.

The unchecked exception classes are the runtime 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.

So yes, the compiler definitely knows about RuntimeException.