java异常处理

时间:2014-06-05 14:12:26   收藏:0   阅读:293

public void test() throws IOException{
    try(
            BufferedReader br=new BufferedReader(new FileReader("AutoCloseTest.java"));
            PrintStream ps=new PrintStream(new FileOutputStream("a.txt"))
            ){
        System.out.println(br.readLine());
        ps.print("afdadffd");
    }
}
当方法中出现throws时,调用应该使用try catch去捕捉异常。如果不处理该异常,出现此类异常时,交给虚拟机处理。

java异常处理,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!