黑马程序员技术交流社区

标题: 异常处理——抛出异常thorws [打印本页]

作者: yuzt    时间: 2016-11-19 22:46
标题: 异常处理——抛出异常thorws
[Java] 纯文本查看 复制代码
import java.io.*;
public class Demo149 {
        public static void main(String[] args) {
                Father father=new Father();
                father.test1();
        }
}

class Father{
        private Son son=null;
        public Father(){
                son=new Son();
        }
        public void test1(){
                System.out.println("1");
                try {
                        son.test2();                       
                } catch (Exception e) {
                        System.out.println("Father在处理Son的异常");
                        e.printStackTrace();
                }
        }
}

class Son{
        public void test2() throws Exception{//throws Exception抛出程序块的异常,由调用者解决异常
                FileReader fr=null;
                fr=new FileReader("d:\\aaa.txt");
        }
}








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