This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Regarding Finalization Method: If an uncaught exception is thrown during the finalization, the exception is ignored and finalization of that object terminates. My Question is what happens next to the object? After the finalization terminates, does the objects get destroyed or it does nothing?? Sonir
Sonir : Was your question in reference to the finally block of code or was it in reference to the finalize method, which is typically called by the garbage collector after the object is no longer accessible from any reference?
Joined: Nov 01, 2001
finalize() method.. ??
Joined: Jan 11, 2002
I thought so too. Your question has nothing to do with the finally block. Finalization can happen on objects that do not have any try/catch/finally blocks at all. This is what the API states of finalize method
The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates. After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.
I believe this means,that even if an exception occurs in the finalize method, the object still remains eligible for garbage collection and it will be garbage collected eventually. HTH
Joined: Jan 18, 2002
I guess I read the question wrong, so to clear up my original reply If the uncaught exception occurs in the clean up of the object's finialize() method then the current execution of the program is aborted, but the exception is ignored! btw, there is nothing preventing a try/catch/finally block from appearing within a finalize method. [ January 21, 2002: Message edited by: Rajinder Yadav ]