jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exceptions 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exceptions" Watch "Exceptions" New topic
Author

Exceptions

Carlo Leeuwen
Greenhorn

Joined: Nov 07, 2007
Posts: 3
Hello,
The question is what will be printed after this code has run:


The answer seems to be:
"The program will print 1, 4 and 5, in that order."

But I don't understand why '5' is printed. After the finally, shouldn't the main method be done? Can anyone explain me?

Thanks in advance!
Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
Hi Carlo,

When a program reaches the end of a "finally" block, it does not then exit the current method. Rather, it continues on to the next line after the whole "try..catch..finally" construct.

Don't be confused by the keyword "finally". Despite the name, it's not that final. It's only "final" with respect to the "try..catch..finally" construct that it's a part of.


SCJP 5.0
Carlo Leeuwen
Greenhorn

Joined: Nov 07, 2007
Posts: 3
Ok thanks, I guess I mixed up some things.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exceptions
 
Similar Threads
952739444280 why?
try /catch problem?
Enthuware questions
unreachable code in 'finally'
Why is 5 getting printed here?