Chapter 17 Exceptions and Assertions.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Chapter 17 Exceptions and Assertions.ppt

Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6 Chapter 17 Exceptions and Assertions Objectives To know what is exception and what is exception handling (§17.2). To distinguish exception types: Error (fatal) vs. Exception (non-fatal), and checked vs. uncheck exceptions (§17.2). To declare exceptions in the method header (§17.3). To throw exceptions out of a method (§17.3). To write a try-catch block to handle exceptions (§17.3). To explain how an exception is propagated (§17.3). To rethrow exceptions in a try-catch block (§17.4). To use the finally clause in a try-catch block (§17.5). To know when to use exceptions (§17.6). To declare custom exception classes (§17.7 Optional). To apply assertions to help ensure program correctness (§17.8). Syntax Errors, Runtime Errors, and Logic Errors You learned that there are three categories of errors: syntax errors, runtime errors, and logic errors. Syntax errors arise because the rules of the language have not been followed. They are detected by the compiler. Runtime errors occur while the program is running if the environment detects an operation that is impossible to carry out. Logic errors occur when a program doesnt perform the way it was intended to. Runtime Errors Catch Runtime Errors Exception Classes System Errors Exceptions Runtime Exceptions Checked Exceptions vs. Unchecked Exceptions Unchecked Exceptions Checked or Unchecked Exceptions Declaring, Throwing, and Catching Exceptions Declaring Exceptions Every method must state the types of checked exceptions it might throw. This is known as declaring exceptions. public void myMethod() throws IOException public void myMethod() throws IOException, OtherException Throwing Exceptions When the program detects an error, the program can create an instance of an appropriate exception type and throw it. This is known as throwing an exception. Here is an example, throw new TheException();

文档评论(0)

shengyp + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档