package cn.javass.hello.servletimpl.vo;
import java.io.*;
public class TestFinally
{
public static void main(String[] args)
{
FileInputStream fs=null;
try{
fs=new FileInputStream("a.txt");
}catch(IOException e){
System.out.println(e.getLocalizedMessage());
System.out.println(e.getMessage());
System.out.println(e.toString());
e.printStackTrace();
return ;
//System.exit(1);
}finally{
if(fs!=null){
try{
fs.close();
}catch(Exception e){
e.printStackTrace();
}
}
System.out.println("程序始终要执行finally里的代码!");
}
System.out.println("Hello World!");
}
}
java中异常处理finally代码块的处理
最新推荐文章于 2023-04-06 19:15:50 发布
本文深入探讨了Java中使用finally块进行异常处理的方法,包括如何捕获IOException,使用try-catch-finally结构,以及确保资源在程序执行结束时得到正确关闭。
249

被折叠的 条评论
为什么被折叠?



