This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

finalize method

 
Dhanashree Mankar
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic