try catch finally{ }里的顺序问题

来源:百度知道 编辑:UC知道 时间:2024/05/17 06:55:51
catch{
system.out.println("catch");
return
}
finally{
system.out.println("finally");
}
这个语句肯定输出的catch,finally,但是我的问题是,return是执行以后再输出finally还是碰到return就转移到finally,最后再来return。
一时刻没有想到怎么来证明。另外就是有没有办法,能让finally里的语句不执行?(根据我所知道的是没有)

1 方法返回前,一定执行finally

2 想不执行,只有终止程序,比如

catch(){
System.exit(0); // 这时,finally 是不会执行的。

应该是碰到return就转移到finally,最后再来执行return,这是基本的语法。