"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.
"...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.
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
Joined: Aug 26, 2000
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).]
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).]