Though the exception is raised the object will be garbage collected. if the finalize method in your progam throws an exception it must be enclosed in an try catch block otherwise it gives a compiler error. hope it helps!.
<<if the finalize method in your <br /> progam throws an exception it must <br /> be enclosed in an try catch block.<br /> >>> if we override the finalize method (protected void finalize throws Throwable),we can make it to throw any exception in the throws clause ,so its not necessary to have a try-catch block as the above sentence says. Please correct me if I am wrong. Mousami
Hi Everyone, Let me explain two things about exceptions : 1) If a method throws a checked exception then the method must have a try catch contruct , or, the method should declare that it throws a checked exception so that the calling method can appropraite action. 2) Runtime exception need to be caught. JVM takes care of it. Now, having said that, lets see what happens when you override the <code>finalize()</code> method of the Object class. First of all you must make sure to call the base class's (i.e, Object) finalise() , by making a call to <code>super.finalize()</code>. If the finalize() method throws a checked exception then it should declare that it throws so that JVM can take appropraite safegaurds. Else the overloaded finalize() method should itself take steps to handle it by having a try catch block. Hope this clears the issue. Ravindra Mohan.
If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates. Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.
Based on the above, any exceptions, wether thrown or caught, will be ignored. If the gc determines that the object is unreachable it will be gc'd; so even if the finalize method does not complete ie terminates because of an exception, the object will still be gc'd if it has no references. You do not have to call the superclass finalize method however it is considered good programming practice to do so. Hope that helps. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform