hi mohamed
what will happen if a checked exception is thrown from the code of finalize() method ?when the object is to be garbage collected?
Let me use some coding to point out what happen if a checked exception is thrown from the code of finalize() method ?
public static void main(String[] argv)
{
try
{
finalize();//(c)
}
catch(IOException ioE)
{
System.out.println("file point to null");//(d)
}
finally
{
System.out.println("Finish");(e)
}
}
public static void finalize() throws IOException
{
File file=null;
FileWriter fw =new FileWriter(file); //(a)
System.out.prinln("Arrive forest"); //(b)
}
if a checked exception is thrown from the code of finalize() method,
firstly,(a) exception occur,it will jump out the method and create the IOException object,so (b) is not excecuted
then,the IOException object catch from the catch IOException handler,so print
file point to null (d)
And the IOException object will be collected after this catch handler,then print
Finish (e)
If it is not clear,please post again
