动手动脑:finally语句块一定会被运行吗
运行
package demo;
public class Demo2 {
public static void main(String[] args)
{
try{
System.out.println("in main");
throw new Exception("Exception is thrown in main");
//System.exit(0);
}
catch(Exception e)
{
System.out.println(e.getMessage());
System.exit(0);
}
finally
{
System.out.println("in finally");
}
}
}
结果
in main Exception is thrown in main
在catch中,结束程序,finally将不被执行

浙公网安备 33010602011771号