Originally posted by zhewen:
haiy all,
one more programm, explain hier in steps please.
class Question {
public static void main(String[] args){
for(int i=0; i<10; i+1){<br /> try{<br /> try { if(i%3==0) throw new Exception("EO");<br /> System.out.println(i);}<br /> catch (Exception inner){<br /> i*=2;<br /> if(i%3==0) throw new Exception("E1");}<br /> finally{++i;}}<br /> catch(Exception outer){<br /> i+=3;}<br /> finally{--i;}}} <br /> the programm don't display 7 or 8, why?
<br /> If you pen and paper this when i = 6 an E0 exception is thrown. In the catch, i*=2 give 12, this causes an E1 exception to be thrown, the finally execute ++i = 13 in the catch for outer i+=3 is 16 in the finally --1 = 15, increment i in the for loop 16,<br /> 16 > 10 for loop ends!