hi jiapei,
it is perfectly legal to have a try and finally block without a catch block:
public class ex
{
public static void main(
String[] str)
{
try
{
int i=5/0;
System.out.println("try block executed");
}
finally
{
System.out.println("finally block executed");
}
System.out.println("main is executed");
}
}
compiles perfectly but an Arithmetic Exception / by zero is thrown. The code in finally block will be executed and it prints: finally block executed
but the method(and program) will be terminated so none of the statements
System.out.println("main is executed");
System.out.println("try block executed");
will be executed though.