File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes finally block vs normal-out-of-try-catch-scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "finally block vs normal-out-of-try-catch-scope" Watch "finally block vs normal-out-of-try-catch-scope" New topic
Author

finally block vs normal-out-of-try-catch-scope

Ian Cabigon
Greenhorn

Joined: Feb 22, 2010
Posts: 25
Hello,

I'd like to know what is the difference with the following try-catch and try-catch-finally snippets.
Enlighten me please.



Thanks,
Ian
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

If c() is in a finally block, it is executed even if b() throws an exception, or a() throws something that doesn't match the catch block. Without the finally, c() wouldn't execute if either of those things happened.


[Jess in Action][AskingGoodQuestions]
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Thanks Ernest Friedman-Hill


Life is easy because we write the source code.....
Ian Cabigon
Greenhorn

Joined: Feb 22, 2010
Posts: 25
Thank you. I finally got it.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Ernest Friedman-Hill wrote:If c() is in a finally block, it is executed even if b() throws an exception, or a() throws something that doesn't match the catch block. Without the finally, c() wouldn't execute if either of those things happened.


additionally, if try has any return statement, then c() without finally fails to execute
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: finally block vs normal-out-of-try-catch-scope
 
Similar Threads
Question from 4tests.com
Exception Handling Question from Dan Chisholm's mock exam
IBM Mock Exam: Try Catch Finally ?
exeption handling
Finally block