JAVA零的基础讲义ch006.pptVIP

  • 3
  • 0
  • 约6.59千字
  • 约 40页
  • 2018-02-18 发布于浙江
  • 举报
创造自己的异常 形如: class MyException extends Exception {….}; 例1 :计算两个数之和,当任意一个数超出范围时,抛出自己的异常 public class NumberRangeException extends Exception { public NumberRangeException(String msg) { super(msg); } } * 第六章 异常处理 异常的概念 什么是异常 异常实际上是程序中错误导致中断了正常的指令流的一种事件. 类型 一种是编译时错误 另一种是运行时错误 逻辑错误 运行环境引起的错误 没有异常处理的程序 没有处理错误的程序: read-file { openTheFile; determine its size; allocate that much memory; closeTheFile; } 常规错误处理方法 openFiles; if (theFilesOpen) { determine the lenth of the file; if (gotTheFileLength){ allocate that much memory; if (gotEnoughMemory)

文档评论(0)

1亿VIP精品文档

相关文档