File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exceptions" Watch "Exceptions" New topic


Carlo Leeuwen

Joined: Nov 07, 2007
Posts: 3
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

Joined: Nov 07, 2007
Posts: 3
Ok thanks, I guess I mixed up some things.
I agree. Here's the link:
subject: Exceptions
It's not a secret anymore!