南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)异常处理 Exception Handling

Exception Handling 异常处理 Institute of Computer Software 2021/2/9 Nanjing University
异常处理 Exception Handling 2021/2/9 Institute of Computer Software Nanjing University 1

R病 这摘要 口简介 口Java异常处理 口 Java Exception机制的不当使用示例 n Effective Java Exceptions 口 Eiffel异常处理 小结 nstitute of Computer Software 2021/2/9 Nanjing University
摘要 简介 Java 异常处理 Java Exception机制的不当使用示例 Effective Java Exceptions Eiffel 异常处理 小结 2021/2/9 Institute of Computer Software Nanjing University 2

R病 回顾DbC a DbC vs Defensive Programming 口DP中产生异常的语句是程序体本身的组成部分 口DbC中 Precondition还是程序文档的组成部分 a Check our dbc demo nstitute of Computer Software 2021/2/9 Nanjing University
回顾DbC DbC vs Defensive Programming DP中产生异常的语句是程序体本身的组成部分 DbC中Precondition还是程序文档的组成部分 Check our DbC demo… 2021/2/9 Institute of Computer Software Nanjing University 3

R病 简介 口问题 口何谓“异常( Exception) 种情况要“异常”到什么程度才算“异常 口为什么要引入异常处理机制? Robustness? Readability 口如何进行异常处理? Mandatory or Optiona 口不同的认识,不同的答案 口Java/C++/C# o Eiffe nstitute of Computer Software 2021/2/9 Nanjing University
简介 问题 何谓“异常(Exception)”? ◼ 一种情况要“异常”到什么程度才算“异常”? 为什么要引入异常处理机制? ◼ Robustness? Readability? 如何进行异常处理? ◼ Mandatory or Optional 不同的认识,不同的答案 Java/C++/C# Eiffel 2021/2/9 Institute of Computer Software Nanjing University 4

R病 A Java Exception Mechanisms 5 口Java对 Exception的界定较宽 口因而需认真区分不同类型的 Exceptions Java的 Exception机制回顾 a try/ catch/find a throw Exceptions 口自定义 Exceptions 口 Java Exception与 Design by Contract 口 Exception的转换 nstitute of Computer Software 2021/2/9 Nanjing University
Java Exception Mechanisms Java 对 Exception 的界定 较宽 因而 需 认真区分 不同类型的 Exceptions Java的Exception机制回顾 try/catch/finally throw Exceptions 自定义Exceptions Java Exception与Design by Contract Exception的转换 2021/2/9 Institute of Computer Software Nanjing University 5

R病 f Understanding Java Exceptions 6 口这部分使用 Manchester University, Kung- Kiu lau CS3101的 PPT SLides nstitute of Computer Software 2021/2/9 Nanjing University
Understanding Java Exceptions 这部分使用Manchester University, Kung-Kiu Lau, CS3101 的PPT Slides 2021/2/9 Institute of Computer Software Nanjing University 6

What are EXceptions? Manyexceptional things can happen during the running of a program, e.g User mis-types input checked Web page not available File not found Array index out of bounds unchecked Method called on a null object Divide by zero Out of memory sys errors Bug in the actual language implementation EXceptions are unexpected conditions in programs
7 What are Exceptions? Many “exceptional” things can happen during the running of a program, e.g.: • Bug in the actual language implementation • User mis-types input • Web page not available • File not found • Divide by zero • Array index out of bounds • Method called on a null object • Out of memory Exceptions are unexpected conditions in programs. checked unchecked sys errors

We can distinguish 3 categories checked exceptions- Problems to do with the program's interaction with"the world unchecked exceptions The world is unpredictable, so we itself(i.e. violations of the d would expect these things to system errors- Problems happen in proa ation code, and so nee These are outside our contron These should be removed by testing and not occur in production code The World Checked EXceptions Unchecked Program Exceptions System System Errors 8
8 We can distinguish 3 categories: • checked exceptions — Problems to do with the program's interaction with “the world”. • unchecked exceptions — Problems within the program itself (i.e. violations of the contract, or bugs). • system errors — Problems with the underlying system. These are outside our control. The world is unpredictable, so we would expect these things to happen in production code, and so need to handle them. These should be removed by testing, and not occur in production code. Unchecked Exceptions System Errors Program System The World Checked Exceptions

Checked vs Unchecked Exceptions an important distinction which the Java it's normal to let these pn class hijerawe woe normay theck for just crash the program h a rather conthese, and deal with them so we can debug it when they occur The World Checked Exceptions Unchecked Program EXceptions System System Errors Exception handling is the business of handling these things appropriately 9
9 Checked vs Unchecked Exceptions Unchecked Exceptions System Errors Program System The World Checked Exceptions an important distinction, which the Java Exception class hierarchy does make, but in a rather confusing way we would normally check for these, and deal with them when they occur. it's normal to let these just crash the program so we can debug it. Exception handling is the business of handling these things appropriately

EXception Hierarchy in Java Throwable Exception RuntimeExcep七ion Excep The Run七 imeException World Checked RuntimeException EXceptions Unchecked Program E卫。 EXceptions System System Errors 10
10 Exception Hierarchy in Java Throwable Exception RuntimeException Error . . . Unchecked Exceptions System Errors Program System The World Checked Exceptions Error RuntimeException Exception − RuntimeException
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 中国科学技术大学:云计算基本概念、关键技术、应用领域及发展趋势.pptx
- 《C程序设计》课程电子教案(PPT课件讲稿)第二章 基本数据类型及运算.ppt
- 《电子商务概论》课程教学资源(PPT课件)第十章 电子商务安全技术.ppt
- 中国铁道出版社:《局域网技术与组网工程》课程教学资源(PPT课件讲稿)第4章 Windows Server系统工程.ppt
- 《Internet技术与应用》课程PPT教学课件(讲稿)第3讲 双绞线制作和传输介质.ppt
- jQuery个人主页(PPT讲稿).ppt
- 《数据结构》课程教学资源(PPT课件讲稿)第10章 内排序.ppt
- 最小生成树(PPT课件讲稿)Minimum Spanning Trees.pptx
- 中国科学技术大学:《数据结构与数据库》课程教学资源(PPT课件讲稿)第五章 串和数组.pps
- 上海交通大学:《网络科学导论》课程PPT教学课件(Network Science An Introduction)Chapter 4 Degree Correlations & Community Structure.pptx
- 同济大学:《大数据分析与数据挖掘 Big Data Analysis and Mining》课程教学资源(PPT课件讲稿)Decision Tree.ppt
- 《软件工程》课程教学资源(PPT课件讲稿)详细设计.ppt
- 《汇编语言程序设计》课程教学资源(PPT课件讲稿)第二章 IBM-PC微机的功能结构.ppt
- 清华大学:高校信息化建设理论与规划(PPT讲稿).ppt
- 数据挖掘10大算法产生过程(PPT讲稿).ppt
- 《计算机文化基础》课程教学资源(PPT课件讲稿)第九章 多媒体技术基础.ppt
- 香港浸会大学:Computer Security(PPT课件讲稿)Cryptography Chapter 1 Symmetric Ciphers.ppt
- 同济大学:《大数据分析与数据挖掘 Big Data Analysis and Mining》课程教学资源(PPT课件讲稿)Getting to Know Your Data.ppt
- 《计算机系统安全》课程PPT教学课件(信息安全与管理)第九章 防火墙.ppt
- 《计算机网络》课程教学资源(PPT课件讲稿)第六章 传输层.ppt
- 《计算机系统结构》课程教学资源(PPT课件讲稿)第三章 流水线技术.ppt
- 四川大学:Object-Oriented Design and Programming(Java,PPT课件)3.2 Graphical User Interface.ppt
- 《编辑原理》课程教学资源(PPT课件)目标代码生成.pptx
- 上海交通大学:操作系统安全(PPT课件讲稿)设备管理与I/O系统.pps
- 中国科学技术大学:《计算机体系结构》课程教学资源(PPT课件讲稿)第7章 多处理器及线程级并行 7.1 引言 7.2 集中式共享存储器体系结构.pptx
- 《单片机原理及应用》课程教学资源(PPT课件讲稿)第11章 单片机应用系统的串行扩展.ppt
- 西安电子科技大学:《数据库系统 DataBase System》课程教学资源(PPT课件讲稿)normalization.ppt
- 《计算机软件技术基础》课程教学资源(PPT课件讲稿)排序(教师:曾晓东).ppt
- 四川大学:《计算机网络 Computer Networks》课程教学资源(PPT课件讲稿)Unit5 Introduction to Computer Networks.ppt
- 《微型计算机原理及接口技术》课程电子教案(PPT课件)第9章 AT89S52单片机的I/O扩展.ppt
- 《数据挖掘导论 Introduction to Data Mining》课程教学资源(PPT课件讲稿)Data Mining Classification(Basic Concepts, Decision Trees, and Model Evaluation).ppt
- 《计算机组成与设计》课程教学资源(PPT课件讲稿)第2章 指令——计算机的语言.ppt
- 清华大学:Local Area Network and Ethernet(PPT课件讲稿).pptx
- 《密码学》课程教学资源(PPT课件讲稿)第10章 密码学的新方向.ppt
- 《计算机系统安全》课程教学资源(PPT课件讲稿)第七章 公开密钥设施PKI Public key infrastructure.ppt
- 《数字图像处理》课程PPT教学课件(讲稿)第四章 点运算.ppt
- 《编译原理》课程教学资源(PPT课件讲稿)第八章 代码生成.ppt
- Introduction to Convolution Neural Networks(CNN)and systems.pptx
- 华北科技学院:数字视频教学软件与制作(PPT课件讲稿)数字视频编辑软件Premiere 6.5(主讲:于文华).ppt
- 中国科学技术大学:《Linux操作系统分析》课程教学资源(PPT课件讲稿)文件系统.ppt