and before return ,the finally block will execute,and the value of i should be 1,and then return i,output will 1.but the result is 0.cloud someone tell me why? thanks in advance
[ September 07, 2005: Message edited by: dx wu ] [ September 07, 2005: Message edited by: Michael Ernest ]
This is not the result I expected either. After playing with the code a bit, I suspect here is what happens...
1)In the try block array element 5 is accessed generating an ArrayIndexOutOfBoundsException.
2)The exception is caught and the "return i" statement is executed in the catch block. The variable "i" at this point has a value of 0 which the JVM stores off as the return value for the function.
3) The finally block is executed. The variable "i" is incremented, but this has no effect on the value returned by the function, because the return statement has already executed in step #2.
4) The method exits with the return value that was saved off by the JVM in step #2. [ September 08, 2005: Message edited by: Todd Johnson ]