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

finalize method

Dhanashree Mankar
Ranch Hand

Joined: Aug 25, 2003
Posts: 123
protected void finalize() throws Throwable
please tell me about the exceptions thrown if finalize method is overrided.
(Both checked and uncheked)
Anupreet Arora
Ranch Hand

Joined: Jun 17, 2003
Posts: 81
Hi,
finalize() method can throw any exception, checked, unchecked whatsoever. The point to note is that if an excption is thrown by finalize, then the exception will be ignored, and the finalization process of the object will be terminated.
So if it is overridden, your version should be able to throw any exception that you want it to throw, because your exception will be a subclass of throwable.
Here is what the API says about it
If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.
Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored

Regards,
Anupreet
 
jQuery in Action, 2nd edition
 
subject: finalize method
 
Similar Threads
difference between finally and finalize()
finalize
Gc question
why finalize() can't be defined as private?
Finalization Method