• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
Ranch Hand
Posts: 1245
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"The exceptions raised in finalize() are ignored. Meaning the JVM will not try search the stack to find the exception handler."

happy new year.
 
Enthuware Software Support
Posts: 4308
35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"...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
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the exception is thrown in a finalizer but not handled then it is ignored by JVM
 
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
High Plains Drifter
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Fei Ng
Ranch Hand
Posts: 1245
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!