Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Hi all, i am confused about the way the return works ... say if i have a return in the try block and something in the finally.. this is the prog..
the following gets printed.. ---------------------- in try ii =1 inside finally..ii = 2 in main ii = 1 ----------------------- now the question is .. The return should give the control back to the calling procedure.. But i do not see it happening here. The control is returned (i guess) to the main the vaule of ii is printed as 1 and then the ii++ takes place and the statement in the finally is executed.. How does this happpens..Does it mean that the statements in the finally get executed after the return ? if not then whats the logic..?? Thanks in advance...
The finally block gets to execute last - even if the try or catch block returns. Note that the return value of the try or catch block would not be used if the finally block were to return (which it does not have to do if the try or catch blocks have already done so). Of course, if the try or catch block were to throw an exception or close the JVM, then the finally block might not get a chance to execute.
Originally posted by Dirk Schreckmann: Of course, if the try or catch block were to throw an exception or close the JVM, then the finally block might not get a chance to execute.
I think the semantic of a finally block is to *always* get executed before controll is given back to the caller, no matter what. A killed JVM might be an exception, of course... :roll:
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
the try/catch/finally construct is a derivative of C++, which in turn derives this feature from 'jump' instructions that appear in ISO C as setjmp() and longjmp(). These in turn derive from CPU instructions by the same name, but that's drilling a bit deep. In short, each of these constructs alters the expected trace of bytecode instruction processing. The bytecode that are invoked by finally are defined to precede any return instruction that might occur in try or catch.
Make visible what, without you, might perhaps never have been seen. - Robert Bresson
And inside of my fortune cookie was this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss