• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

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()
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic