Arvind,
To make our discussions easier, I just print the output of our program in both cases with and without the 'return i;' statement in 'inner finally' block.
What happens is , when 10/0 is calculated, an 'ArithmeticException' is thrown. But there is no catch block for this exception, in inner try..catch..finally block. So before trying to the next level [ in our case, which is the next immediate surrounding block, which is outer try..catch..finally block ] , finally of inner try..catch...finally is executed.
So what happens here is the 'println' statement is executed. UPTO this point the ArithmeticException is carried over. But when JVM sees the return i statement, the cause of this abnormal completion of inner 'try block' which is
Arithmethic Exception is DROPPED. The reason for this DROPPING OF CAUSE (Arithmetic Exception) is again 'abnormal completion of finally block' of this inner try..catch..finally block , because of the 'return i' statement.
Reference from JLS :
Whenever there is a return statement in a chunk of statements, the execution of such statements are said to
complete abruptly So bottom line is,
1. If execution of the try block completes abruptly due to Arithmetic Exception (the cause)
2. There is no catch block for this ArithmeticException
3.The inner finally block completes abruptly for reason 'return i' statement , so the inner try statement completes abruptly for cause 'return i' statement (and previous cause 'ArithmeticException' is discarded).
Also Arvind,
I give you the exact JLS portion which clearly says this above concept. Please read it very carefully. It clearly says the reason, why our output is like this.
References from JLS:
14.18.2 Execution of try-catch-finally
---------------------------------------
http://java.sun.com/docs/books/jls/html/14.doc.html#236653 14.1 Normal and Abrupt Completion of Statements
-----------------------------------------------
http://java.sun.com/docs/books/jls/html/14.doc.html#5894 14.15 The return Statement
--------------------------
http://java.sun.com/docs/books/jls/html/14.doc.html#6767 Did all above information convince you ?

regds
maha anna
[This message has been edited by maha anna (edited December 30, 2000).]