This is your code and below is the explanation
class Test{
public static void main(String Args[]){
for (int i=0; i< 10; ++i){
try{
if( i%3 ==0) throw new Exception("EO");// stat 1
try{
if(i%3==1) throw new Exception("E1");//stat 2
System.out.println(i);
}catch(Exception inner){ //stat 3
i*=2;
} finally {
++i;
}
}catch (Exception outer){ //stat4
i +=3;
}finally{
++i;
}
}
}
}
at stat1
//when i=0,it throws Exception and goes corresponding catch{Exception outer},then i=3 and then executes finally block,so now i=4;Now it goes in the for loop and i=5(because of ++i)
now 5%3!=0 so it does not throw exception at stat1,then the control moves to stat2
again 5%3!=1 so does not throw exception at stat2..
So prints 5
then it excecutes both the finally statments and the i =7,then it moves in the
for loop (before going to the loop ,++i is done) so i=8 and i%3!=0 so does not thrwo exception at stat1,the then the control moves to stat2
again 8%3!=1 so does not throw exception at stat2..
So prints 8.Again executes both the finally statements and the i=10 so does not
go in the loop
Hope that helps
Alpa-urja