aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes finalize and finalizer : Need clarification Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "finalize and finalizer : Need clarification" Watch "finalize and finalizer : Need clarification" New topic
Author

finalize and finalizer : Need clarification

Mathew Kuruvilla
Ranch Hand

Joined: Nov 27, 2001
Posts: 135
A finalize method may throw exceptions and not finish.
However any exception thrown but not caught by a finalizer when invoked by the garbage collector is ignored.
Which of the above is true?
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
It sounds to me like they say the same thing. What conflict do you see?
Mathew Kuruvilla
Ranch Hand

Joined: Nov 27, 2001
Posts: 135
A finalize method may throw exceptions and not finish.
=> In other words, if the garbage collector calls the finalize method for an object and the call results in an exception and this exception is not caught, the method returns from that point back to the garbage collector.
However any exception thrown but not caught by a finalizer when invoked by the garbage collector is ignored.
=>In other words, if the garbage collector calls the finalizer for an object and the call results in an exception and this exception is not caught, the exception is ignored and the method continues till it is completed.
???
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
From the API for finalize() in Object:
"
If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.
"
The finalize method is halted. The exception is ignored in the sense that is doesn't goes up in the call stack, and it is not printed in the output. However the object is garbage collected.


SCJP2. Please Indent your code using UBB Code
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: finalize and finalizer : Need clarification