Manouti's answer seems to be correct, but according to the java documentation:
This is a compile-time error if the checked E1 exception type is flagged in the catch clause, but there is no E2 exception type for which all of the following operations are performed:
E2 <: E1 A try block that matches the catch clause can call E2. There is no previous catch block that immediately includes a try statement that catches E2 or the supertype E2. if E1 is not an exception to the class.
There is a clear case for throwing an Exception instance (the Exception class is exceptional, you might say). This is Java 5 documentation, but unless someone sees otherwise, I highly doubt it has changed since
Looking at inheritance tree for Exception and IOException
https://docs.oracle.com/javase/7/docs/api/java/lang/Exception.html
and
https://docs.oracle.com/javase/7/docs/api/java/io/IOException.html?is-external=true
in Java 7, I donβt see that the discussion of Checked / Unchecked exceptions is directly relevant - while it is true that the excepted exceptions do not follow the same rules, unchecked exceptions should inherit from RuntimeException , which of course is no Exception (it is the parent this class)
https://docs.oracle.com/javase/specs/jls/se5.0/html/classes.html#308526
(again, Java 5 docs, but it hasn't changed) https://docs.oracle.com/javase/specs/jls/se5.0/html/exceptions.html
source share