C
Chris Riesbeck
Shouldn't the code below finish with an IllegalStateException, after the
finally is executed? That's how I read Section 14.20.2 of the 3rd
edition of the language spec. But with jdk1.5.0_06 on Windows XP, I'm
getting the output "returned with no exception."
14.20.2 Execution of try–catch–finally BLOCKS AND STATEMENTS
"... If the catch block completes abruptly for reason R, then the
finally block is executed. Then there is a choice:
- If the finally block completes normally, then the try statement
completes abruptly for reason R..."
public class TryCatchFail {
public static void main(String[] args) {
System.out.println(doWithFinally());
}
private static String doWithFinally() {
try {
throw new IllegalArgumentException("io exception");
}
catch (IllegalArgumentException exc) {
throw new IllegalStateException(exc);
}
finally {
return "returned with no exception";
}
}
}
finally is executed? That's how I read Section 14.20.2 of the 3rd
edition of the language spec. But with jdk1.5.0_06 on Windows XP, I'm
getting the output "returned with no exception."
14.20.2 Execution of try–catch–finally BLOCKS AND STATEMENTS
"... If the catch block completes abruptly for reason R, then the
finally block is executed. Then there is a choice:
- If the finally block completes normally, then the try statement
completes abruptly for reason R..."
public class TryCatchFail {
public static void main(String[] args) {
System.out.println(doWithFinally());
}
private static String doWithFinally() {
try {
throw new IllegalArgumentException("io exception");
}
catch (IllegalArgumentException exc) {
throw new IllegalStateException(exc);
}
finally {
return "returned with no exception";
}
}
}