Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between finally and no finally.

 
Erik Pragt
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if this subject doesn't make it clear, I have no idea what does
My question is a small and simple one, but I have no idea what the solution is.
Suppose you have the following 2 pieces of code:

and you have the other piece of code:

Then what's the difference? The only thing I can come up with it that in the former pierce of code, you can throw an Exception and still return the String, and in the latter you can't. However, I have no idea if this interpretation of mine is correct.
Thanks for your help,
Erik Pragt

-- and a happy new year!!!
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a learning experience, fill in some of the "do something"s and run the resulting programs...
 
Erik Pragt
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right. I actually came up with the last paragraph in my previous post, so I haven't tested that you.
Greetings, Erik
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the first code sample, the return statement will execute even if an exception was thrown inside the catch block. This is not so, in the 2nd example.
Pho
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic