- 1、本文档共40页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Java程序设计 Java Programming Spring, 2009 Contents Why Exceptions? What are Exceptions? Handling Exceptions Creating Exception Types Why Exceptions? During execution, programs can run into many kinds of errors; What do we do when an error occurs? Java uses exceptions to provide the error-handling capabilities for its programs. Exceptions Error Class Critical error which is not acceptable in normal application program. Exception Class Possible exception in normal application program execution; Possible to handle by programmer. Exceptions An exception is an event that occurs during the execution of a program that disrupts(使中断) the normal flow of instructions. Treat exception as an object All exceptions are instances of a class extended from Throwable class or its subclass. Generally, a programmer makes new exception class to extend the Exception class which is a subclass of Throwable class. Classifying Java Exceptions Unchecked ExceptionsIt is not required that these types of exceptions be caught or declared on a method. Runtime exceptions can be generated by methods or by the JVM itself. Errors are generated from deep within the JVM, and often indicate a truly fatal state. Checked ExceptionsMust either be caught by a method or declared in its signature by placing exceptions in the method signature. Exception的分类 检查性异常(checked exception): 一般程序中可预知的问题,其产生的例外可能会带来意想不到的结果,因此Java编译器要求Java程序必须捕获或声明所有的非运行时异常。以IOException为代表的一些类。如果代码中存在检查性异常,必须进行异常处理,否则编译不能通过。如:用户连接数据库SQLException、FileNotFoundException。 非检查性异常(unchecked exception): 以RuntimeException为代表的一些类,编译时发现不了,只在能运行时才能发现。 Exception的分类 Runtime Exception: Java虚拟机在运行时生成的例外,如被0除等系统错误、数组下标超范围等,其产生比较频繁,处理麻烦,对程序可读性和运行效率影响太大。因此由系统检测, 用户可不做处理,系统将它们交给缺省的异常处理程序(当然,必要时,用户可对其处理)。 Java程序异常处理的原则是: 对于Error和RuntimeException,可以在程序中进行捕获和处理,但不是必须的。 对于IOException及其他异常,必须在程序进行捕获和处理。异常处理机制主要处理检查性异常。 System-Defined Exception(系统定义的异常) Raised implicitly by system because of illegal execution of program; When cannot continue program exe
您可能关注的文档
最近下载
- 2025新人音版音乐一年级下册(赵季平主编)《第四单元 游戏》大单元整体教学设计[2022课标].pdf
- 医院检验科生物安全实验室人员培训和考核制度.docx VIP
- 劳动防护用品使用安全培训.pptx VIP
- 2024年06月国家税务总局广东省税务局系统公开招聘事业单位工作人员50人笔试近年[2018-2023]典型考题及考点剖析附答案带详解.docx VIP
- 【学习教程】小梅哥Xilinx FPGA自学教程V1.2.pdf
- 宁夏银川一中2020-2021学年高一上学期期末考试语文试题 Word版含答案.doc VIP
- 《刑事诉讼法》 课件 (高教-马工程) 第0--16章 绪论、马克思恩格斯的刑事诉讼观--死刑复核程序.pptx
- 《1-12月绿化养护计划》.doc
- 机电施工组织设计(施工方案).docx
- 1.新高一开学第一节班会课《如何适应高中生活》主题班会-(共23张PPT)(2)省公开课获奖课件市赛.pptx
文档评论(0)