Is this Java code legal? Apparently it gets different results on different compilers.
foo throws Exception without declaring it.
If the code in the try block does not declare any exceptions thrown, then we know that any Exception reaching the catch block is RuntimeException, so actually, this is OK.
But that seems to require a deep static code analysis, while a simple syntactic reading of this method says that it is illegal.
Can you refer me to an article or section of the language spec?
public void foo() {// no throws clause
try {
// Lines of code
} catch (Exception e) {
throw e;
}
}