In this code:
try {
f();
d();
} catch (Ex1 ex) {
println("main caught Ex1");
} catch (Ex3 ex) {
println("main caught Ex3");
} finally {
println("main finally");
}
If f()
throws an exception, the try
block will quit. Whether or not the exception is caught, main()
will not call d()
. If there's a catch
block that catches the exception, it will be executed and then the finally
block is executed; otherwise, the finally
block is executed and then the exception is thrown again. But in both cases, d()
will not be called.