This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between finally and no finally.
 
Similar Threads
single return statement: yes / no?
Max, finally { unlock}
Nested Try/Catch
Connection timed out while downloading
Exception Handling