测试finally在return前执行

 

代码
package jdk.base;

/**
*
@author <a href="mailto:czy88840616@gmail.com">czy</a>
*
@since 2010-3-23 22:37:28
*/
public class FinallyDemo {
public static void main(String[] args) {
System.out.println(
"------------");
System.out.println(test());
System.out.println(
"------------");
}

public static boolean test() {
try {
throw new Exception("test finally");
}
catch (Exception e) {
System.out.println(
"in catch");
return true;
}
finally {
System.out.println(
"in finally");
}
}
}

 

输出:

 

------------
in catch
in finally
true
------------

------------

in catch

in finally

true

------------

 

 

结论:return在finally后执行……

posted @ 2010-03-23 22:50  雪霁霜飞  阅读(200)  评论(0编辑  收藏  举报