黑马程序员技术交流社区

标题: 求此题程序执行的顺序 [打印本页]

作者: xwh1230    时间: 2014-7-24 20:25
标题: 求此题程序执行的顺序
写出程序结果
class Demo
{       
        public static void func()
        {
                try
                {
                        throw  new Exception();                               
                                               
                }
                finally
                {
                        System.out.println("B");
                }
        }
        public static void main(String[] args)
        {
                try
                {
                        func();
                        System.out.println("A");
                }
                catch(Exception e)
                {
                        System.out.println("C");
                }
                System.out.println("D");
        }
}



作者: 南柯一梦    时间: 2014-7-24 23:15
输出结果依次是b,c,d,因为执行func方法时,出现异常,执行finallyb,然后catch捕捉异常,执行c,最后执行d




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2