wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes finalize() method of garbage collection...HELP needed.... 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 "finalize() method of garbage collection...HELP needed...." Watch "finalize() method of garbage collection...HELP needed...." New topic
Author

finalize() method of garbage collection...HELP needed....

vikas mehta
Greenhorn

Joined: Dec 28, 2001
Posts: 4
"If an exception is thrown during execution of the finilize() method of an object then the exception is ignored and the object destroyed."
this is a false statement according to khalid mughal Q 8.3

according to java language specification 2.0....
"If an uncaught exception is thrown during the finalization, the exception is ignored and finalization of that object terminates."
i m not able to understand what actually happens...
as again the khalid mughal in the answer to Q 8.3 says...exceptions are not really ignored but handled normally...
plz help.
Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1242
"The exceptions raised in finalize() are ignored. Meaning the JVM will not try search the stack to find the exception handler."

happy new year.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3253
    
    2
"...the exception is ignored and finalization of that object terminates."
This does not clearly tell what happens to the object if the finalization terminates due to an exception. I think, it means "finalization terminates as if nothing (no exception) happened", in which case the object will be destroyed.
HTH,
Paul.

------------------
SCJP2, SCWCD Resources, Free Question A Day, Mock Exam Results and More!
www.jdiscuss.com
Get Certified, Guaranteed!
JQPlus - For SCJP2
JWebPlus - For SCWCD
JDevPlus - For SCJD


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
If the exception is thrown in a finalizer but not handled then it is ignored by JVM
mark stone
Ranch Hand

Joined: Dec 18, 2001
Posts: 417
If the exception is thrown in a finalizer but not handled then it is ignored by JVM ........
and even if it is handled ok then also it is ignored. right ? is this correct as well ?
Originally posted by Ragu Sivaraman:
If the exception is thrown in a finalizer but not handled then it is ignored by JVM

Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

The gc calls finalize() on a fully dereferenced object, and catches any exception that finalize() throws. Since Object.finalize() throws Throwable, you can guess that the gc is ready for anything.
Ignoring uncaught exceptions is the VM's way of saying finalize() can't get around it by throwing "the unexpected." That is, you cannot write a garbage collector that would throw an uncatchable finalize() exception and cause the VM to crash. But if the exception is caught, there's no reason not to process it.
Another way to read this rule: the gc uses a finally block (or its functional equivalent) to guarantee it has the last word on collection.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1242
thanks Michael ,
i have some doubt about it too.
it is very clear now.


[This message has been edited by FEI NG (edited January 01, 2002).]
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
In a nutshell: if an exception is thrown when gc executes finalize, this method ends. But the object is recycled as if no exception was thrown (or finalize would have completed normally)
[This message has been edited by Jose Botella (edited January 01, 2002).]


SCJP2. Please Indent your code using UBB Code
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: finalize() method of garbage collection...HELP needed....
 
Similar Threads
finalize method
Finalization Method
Regarding object finalization
another question regarding garbage collection
Clarification