接上一篇,跟上一篇代码差不多,就是修改了a的值为double类型。
public class TryTest
{
public static void main(String[] args)
{
TryTest tt = new TryTest();
tt.test1();
System.out.println();
tt.test2();
System.out.println();
tt.test3();
}
public void test1()
{
double a = 2.0;
System.out.println("start");
try
{
a = a/0;
}catch(Exception e)
{
System.out.println("catch");
}finally
{
System.out.println("finally");
}
System.out.println("end");
}
public void test2()
{
double a = 2.0;
System.out.println("start");
try
{
a = a/0;
}catch(Exception e)
{
System.out.println("catch");
return;
}finally
{
System.out.println("finally");
}
System.out.println("end");
}
public void test3()
{
double a = 2.0;
System.out.println("start");
try
{
a = a/0;
}catch(Exception e)
{
System.out.println("catch");
System.exit(0);
}finally
{
System.out.println("finally");
}
System.out.println("end");
}
}
输出为:
start
finally
end
start
finally
end
start
finally
end