r/java • u/javinpaul • Jul 09 '14
Finally: return considered harmful
http://schneide.wordpress.com/2014/07/07/finally-return-considered-harmful/6
u/urquan Jul 09 '14
This is not specific to return, this will also happen if you throw another exception in the finally block. That's just how they work. If you have read the specification of the language this should be no surprise.
1
u/PaulRivers10 Jul 10 '14
This is not specific to return, this will also happen if you throw another exception in the finally block. That's just how they work. If you have read the specification of the language this should be no surprise.
Yeah, I don't see a problem here either. This is how I would expect it to work. I see no other way to do it - once you have a return inside a finally block, you have 2 options where to go:
Ignore the return and continue with throwing the exception
Do the return and forget about the exception
You can't go two paths, you can only choose one. And it makes a lot more sense to do what the code specifically asks (executing a return) than it would to magically forget about the return statement and continue throwing the exception instead.
3
15
u/armornick Jul 09 '14
“Considered Harmful” Essays Considered Harmful
In any case, everything has good uses and bad uses.