Thursday, October 18, 2007

Little Sugar (Handling Exceptions in Finalize )

Lets consider a scenario where you have a class A and a subclass of that class called B.
Now say you override the finalize method in class B then you need to explicitly invoke the
finalize method of the parent.

So your implementation should look like this :

protected void finalize() throws Throwable {
try{
}finally{
super.finalize();
}

}

That way ,
any exceptions thrown in the finalize method would not cause the finalize method to terminate and leave the object in a corrupt state.

No comments: