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.
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.