测试finally在return前执行

 

代码
   
     
package jdk.base;

/**
*
@author <a href="mailto:[email protected]">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后执行……

你可能感兴趣的:(finally)