黑马程序员技术交流社区

标题: 一道容易出错的try{}catch{}编程题 [打印本页]

作者: 炙爱小爱    时间: 2016-4-6 10:36
标题: 一道容易出错的try{}catch{}编程题
class Demo1
{
        public static void function()//throws Exception需要把try里面的Exception进行抛出,否则编译失败。
        {
                try
                {
                        throw new Exception();
                }
                finally
                {
                        System.out.println("B");
                }
        }
        public static void main(String[] args)
        {
                try
                {
                        function();
                        System.out.println("A");
                }
                catch (Exception e)
                {
                        System.out.println("C");
                }
                System.out.println("D");
        }
}
//输出结果B C D




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