Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Can finalize() throw Exception?

 
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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()
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic