In Java, checked exceptions are all instances of Throwable, except the instances of Error and RuntimeException. More specifically, if a class extends Exception, but not RuntimeException, it will be considered a checked exception.
This is why, for catch blocks catching a checked exception, the compiler checks if it can be actually thrown from the try block and reports a compiler error if this isn't the case:
import java.io.IOException;
public class ExceptionTest5 {
public static void main(String[] args) {
try{
} catch (IOException e) {
}
}
}
ExceptionTest5.java:10: error: exception IOException is never thrown in body of corresponding try statement
which wouldn't be reported if RuntimeException was in the catch block.
However, nothing is being reported if Exception or Throwable are in the catch block, which makes them act like they were unchecked exceptions - which is directly opposed to the first sentence of this post, which I found in many different sources.
So, is Exception a checked or unchecked exception?