Quoting the Java Language Specification, ยง11.2.3:
It is a compile-time error if a catch clause can catch checked exception class E1 and it is not the case that the try block corresponding to the catch clause can throw a checked exception class that is a subclass or superclass of E1, unless E1 is Exception or a superclass of Exception.
I’m guessing that this rule originated long before Java 7, where multi-catches did not exist. Therefore, if you had a try block that could throw a multitude of exceptions, the easiest way to catch everything would be to catch a common superclass (in the worst case, Exception, or Throwable if you want to catch Errors as well).
Note that you may not catch an exception type that is completely unrelated to what is actually thrown – in your example, catching any subclass of Throwable that is not a RuntimeException will be an error:
try {
System.out.println("hello");
} catch (IOException e) { // compilation error
e.printStackTrace();
}
Edit by OP: The main part of the answer is the fact that question examples work only for Exception class. Generally catching checked exceptions is not allowed in random places of the code. Sorry if I confused somebody using these examples.