Win a copy of Head First Android this week in the Android forum!
  • 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 ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Can finalize() throw Exception?

 
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, can the finalize() throw checked exceptions?
In an answer to a review question (pg. 256 ,8.4 c), it is stated in Khalid Mughal that the finalize() in Object can throw any throwable Object.Overiding methods can limit the range to unchecked exceptions.However, I have overridden the method to throw any Exception(checked) & it works fine.
So help me guys, is it that I am not able to understand the problem correctly or am I right?
Thanks,
Vedhas.
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The finalize() method of Object class is as follows :
protected void finalize() throws Throwable
So if you override the finalize() method in your class and
declare that it throws some checked exception, it is perfectly
fine as it will be a subclass of Throwable.
Overriding method( subclass method ) can always throw subclasses of exception of the overridden(super class) method.
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does it mean that Finalize() can throw unchechked exception and Runtime Exception as well as checked Exception as Finalize() method throws Throwable.
--Farooq
 
Angela Narain
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, any overriding method can throw unchecked (runtime exceptions ) even if the overridden method does not throw them .
 
Angela Narain
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, any overriding method can throw unchecked (runtime exceptions ) even if the overridden method does not throw them .
Same holds true for finalize()
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic