• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

finalize() Exception

Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the follwing class the "protected void finalize()" method gets compiled
public class FinalException {
FinalException() {
System.out.println("Creating FinalException ");
protected void finalize() {
System.out.println("finalizing ");
public static void main(String[] args)
new FinalException();
But when I call the "superclass finalize()"(which is commented in the above code method I get the error that the Throwable exception must be caught. Why the Exception has to be caught only when the superclass finalize() is called.
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you check the API, the finalize method in the Object class (which is what you're calling when you say super.finalize() ) throws a Throwable exception.
You don't get an error when you call the finalize method in your class, because it doesn't throw any exceptions. If you declared your method as follows:
protected void finalize() throws Throwable {
then you would have an exception you'd need to catch, as in the finalize() method from Object.
Hope this helps.
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
a bit of art, as a gift, the permaculture playing cards
    Bookmark Topic Watch Topic
  • New Topic