读书人

在catch中施用throwfinally中的语句

发布时间: 2012-07-05 07:59:18 作者: rapoo

在catch中使用throw,finally中的语句是否会执行?

public class Exceptiontest
{
?? public static void main(String[] args) throws Exception
?? {
??? try{
???? System.out.println("zai try中");
??? }catch(Exception e){
???? System.out.println("zai catch中");
???? throw new Exception("在catch中的throw");
??? }finally{
???? System.out.println("zai finally");
??? }
?? }
}

执行结果是:

zai try中
zai finally

说明:尽管在catch中使用throw,程序依然会执行finally中的语句

读书人网 >软件开发

热点推荐