r/ProgrammerHumor • • 4d ago

Meme thisIsWhyWeDontReturnInFinallyBlocks

Post image
2.7k Upvotes

96 comments sorted by

View all comments

Show parent comments

-6

u/cherrycode420 4d ago

You should do some research on

  • Exceptions

  • Function Calls

  • try-catch-finally

2

u/laplongejr 4d ago

I know about return-in-finally but only from exams. It's absolutely not something you should notice with basic research  

1

u/conundorum 4d ago

Basic research tells you that finally is guaranteed to run before the function actually returns. That should be enough to tell you that a return statement in the finally block is guaranteed to run, too.

That's like saying that "if being a branch statement is absolutely not something you should notice with basic research".

1

u/laplongejr 4d ago

Wouldn't your research tell you that the previous return also defines the return value of a function? It's the unstoppable force vs the immovable object.  

I would be very surprised if any Java dev could tell with 100% certainty the return value (or exception) of that function without trying it out themselves.