M
Matt
I have question on finally block. If exception is catched, the statements inside
finally block and beyond finally block still will execute. Then what's the point
to put finally keyword?? Please advise. Thanks!!
C:\>java ExceptionTest3
abc.txt (The system cannot find the file specified)
inside finally block...
beyond finally block...
--------------------------------------------------------
import java.io.*;
public class ExceptionTest3
{ public static void openFile() throws IOException
{ BufferedReader br = new BufferedReader(new FileReader("abc.txt"));
String line = br.readLine();
br.close();
}
public static void main(String args[])
{ try
{ openFile();
}
catch(Exception e)
{ System.out.println(e.getMessage());
}
finally
{
System.out.println("inside finally block...");
}
System.out.println("beyond finally block...");
}
}
finally block and beyond finally block still will execute. Then what's the point
to put finally keyword?? Please advise. Thanks!!
C:\>java ExceptionTest3
abc.txt (The system cannot find the file specified)
inside finally block...
beyond finally block...
--------------------------------------------------------
import java.io.*;
public class ExceptionTest3
{ public static void openFile() throws IOException
{ BufferedReader br = new BufferedReader(new FileReader("abc.txt"));
String line = br.readLine();
br.close();
}
public static void main(String args[])
{ try
{ openFile();
}
catch(Exception e)
{ System.out.println(e.getMessage());
}
finally
{
System.out.println("inside finally block...");
}
System.out.println("beyond finally block...");
}
}