my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Difference between finally and no finally. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference between finally and no finally." Watch "Difference between finally and no finally." New topic
Author

Difference between finally and no finally.

Erik Pragt
Ranch Hand

Joined: Sep 08, 2001
Posts: 125
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

Joined: Aug 03, 2002
Posts: 7729
As a learning experience, fill in some of the "do something"s and run the resulting programs...


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Erik Pragt
Ranch Hand

Joined: Sep 08, 2001
Posts: 125
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

Joined: Nov 05, 2000
Posts: 761

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


Regards,

Pho
 
GeeCON Prague 2014
 
subject: Difference between finally and no finally.