jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "exceptions" Watch "exceptions" New topic


Martin Smith

Joined: Apr 05, 2003
Posts: 22
look at this code - It's like the exception gets "lost" - odd or what?
Greg Charles

Joined: Oct 01, 2001
Posts: 2967

The purpose of a finally block is to execute some code regardless of how you exit the try block. That is, you could finish executing the try block normally, return from the inside the block, or throw an exception from inside the block. The finally block is great for closing an I/O stream, socket, db connection, or something similar. You've chosen to put a return statement there though. The exception stops execution of the try block, but the finally block still executes and returns true. You cannot both return a value and throw an exception from a method, so the exception "disappears".
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Yup. It's almost always a bad idea to return or throw an exception from a finally clause. Note that the new JDK, j2sdk1.4.2 (beta), will give you a warning when you compile this class:
warning: finally clause cannot complete normally

"I'm not back." - Bill Harding, Twister
Martin Smith

Joined: Apr 05, 2003
Posts: 22
I agree. Here's the link: http://aspose.com/file-tools
subject: exceptions
It's not a secret anymore!