I tried to play around with the code and there's one thing I don't understand. If I have
Code: Select all
public class TestClass {
public static void main(String[] args) {
int j = 1;
int i;
try {
i = doIt() / (j = 2);
System.out.println(i);
} catch (Exception e) {
System.out.println(" j = " + j);
}
}
public static int doIt() throws Exception {
throw new Exception("FORGET IT");
}
}
However, if I add a
Code: Select all
System.out.println(i);
My guess: in the first case, the compiler knows that i might not be intialized and throw an Exception, but will not complain because the println will not be executed in that case.
Could you please point out if there's a flaw in my reasoning or give a little more info on how this works?
Thanks a lot!