posted 18 years ago
Now, when inside amethod(), the try block starts execution:
However, this file does not exist and hence throws a FileNotFoundException which is caught by the catch block:
And here's your confusion: U asked why -1 is being printed after finally block.
Well, after the catch block is executed, control transfers to the finally block. The finally block will be executed after printing "No such file found" from the catch block.
The -1 which is returned from the catch block will be printed only after the control transfers back to the main() method.
Hence after printing "No such file found" exception, control goes straight to the finally block. where you get:
Lastly, the control transfers back from the amethod() to main(). Hence the last thing done is returning the value -1 from amethod().
So -1 is printed in the end.
Hope now the things are crystal clear !!
[ August 09, 2005: Message edited by: Sherry Jacob ]
<strong><br />Cheers !!<br /> <br />Sherry<br /></strong><br />[SCJP 1.4]