第九章 Java异常处理机制.pptVIP

  • 4
  • 0
  • 约6.82千字
  • 约 25页
  • 2018-01-05 发布于河南
  • 举报
第九章 Java异常处理机制

异常的捕获和处理 finally 语句 finally语句为异常处理提供一个统一的出口,使得 在控制流程转到程序的其他部分以前,能够对程序 的状态作统一的管理。 无论try所指定的程序块中是否抛出例外,finally所 指定的代码都要被执行。 通常在finally语句中可以进行资源的清除工作,如 关闭打开的文件、删除临时文件等。 异常的捕获和处理(了解,不做要求) public class Test { public static void main(String[] args) { FileInputStream in = null; try { in = new FileInputStream(myfile.txt); int b; b = in.read(); while (b != -1) { System.out.print((char) b); b = in.read(); } } catch (IOException e) { System.out.prin

文档评论(0)

1亿VIP精品文档

相关文档