The following code compiles and runs on Java 13:
public class CheckedExceptionSSCE {
public static void main(String[] args) {
try {
methodNoThrowsDeclaration();
} catch (Exception e) {
// why is this throw allowed?
// no throws in main()
throw e;
}
}
private static void methodNoThrowsDeclaration() {
System.out.println("doesn't throw");
}
}
How come the throw e is allowed?
Is it specified somewhere in the JLS? I was not able to find it, perhaps I'm using wrong keywords to search.
Is the compiler smart enough to deduce that there will be no real checked exception thrown and thus allows the code to compile and run?