- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
Java程序设计 Java Programming Spring, 2013 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(指令). Exceptions (异常) 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. Exception Class 继承关系 Classifying(分类) Java Exceptions Unchecked Exceptions(非检查性异常) It 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 Exceptions(检查性异常) Must either be caught by a method or declared in its signature by placing exceptions in the method signature. Exception的分类 非检查性异常(unchecked exception): 以RuntimeException为代表的一些类,编译时发现不了,只在能运行时才能发现。 检查性异常(checked exception): 一般程序中可预知的问题,其产生的异常可能会带来意想不到的结果,因此Java编译器要求Java程序必须捕获或声明所有的非运行时异常。 以IOException为代表的一些类。如果代码中存在检查性异常,必须进行异常处理,否则编译不能通过。如:用户连接数据库SQLException、FileNotFoundException。 Exception的分类 什么是Runtime Exception: Java虚拟机在运行时生成的异常,如:被0除等系统错误、数组下标超范围等,其产生比较频繁,处理麻烦,对程序可读性和运行效率影响太大。因此由系统检测, 用户可不做处理,系统将它们交给默认的异常处理程序(当然,必要时,用户可对其处理)。 Java程序异常处理的原则是: 对于Error和RuntimeException,可以在程序中进行捕获和处理,但不是必须的。 对于IOException及其他异常,必须在程序进行捕获和处理。异常处理机制主要处理检查性异常。 Exception的分类 System-Defined Exception(系统
文档评论(0)