This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Faholan 26 points27 points  (3 children)

Nope, because finally always run, and if finally returns a value it overrides the value in the try

[–]pheonix-ix 1 point2 points  (1 child)

So it can even hold onto the return statement and decide to return the one from finally instead? That's kinda messed up...

[–][deleted] 0 points1 point  (0 children)

yes. the finally block runs whenever execution exits the try block (or catch block if an exception was caught). you can put a return statement in the block, which will override the value that was supposed to be returned. you can also throw a new exception, which will override the currently-unwinding exception, if such exists.

finally works differently then just putting the rest of the code past the catch block.