Exception (1) Understanding Exception Handling
When an exception is thrown, it cannot be ignored--there must be some kind of notification or termination of the program. If no user-provided exception handler is present, the compiler provides a default mechanism to terminate the program.
Exceptions are particularly helpful in dealing with situations that cannot be handled locally. Instead of propagating error status throughout the program, you can transfer control directly to the point where the error can be handled.
For example, a function might have the job of opening a file and initializing some associated data. If the file cannot be opened or is corrupted, the function cannot do its job. However, that function might not have enough information to handle the problem. The function can throw an exception object that describes the problem, transferring control to an earlier point in the program. The exception handler might automatically try a backup file, query the user for another file to try, or shut down the program gracefully. Without exception handlers, status and data would have to be passed down and up the function call hierarchy, with status checks after every function call. With exception handlers, the flow of control is not obscured by error checking. If a function returns, the caller can be certain that it succeeded.
Exception handlers have disadvantages. If a function does not return because it, or some other function it called, threw an exception, data might be left in an inconsistent state. You need to know when an exception might be thrown, and whether the exception might have a bad effect on the program state.
Exception (1) Understanding Exception Handling的更多相关文章
- Exception (2) Java Exception Handling
The Java programming language uses exceptions to handle errors and other exceptional events.An excep ...
- Exception (3) Java exception handling best practices
List Never swallow the exception in catch block Declare the specific checked exceptions that your me ...
- Checked Exception与Runtime Exception 的区别
Java里有个很重要的特色是Exception ,也就是说允许程序产生例外状况.而在学Java 的时候,我们也只知道Exception 的写法,却未必真能了解不同种类的Exception 的区别. 首 ...
- vagrant yii2 Exception 'yii\db\Exception' with message 'SQLSTATE[HY000] [2002]
开发环境:vangrant + LAMP 安装了yii2 advanced版本之后,通过url访问fornted 报数据库user表不存在,看了安装yii2 advanced的教程,里面说需要需要运行 ...
- jenkins编辑报错Exception when publishing, exception message的解决办法
jenkins编辑报错Exception when publishing, exception message的解决办法 查看目标主机的磁盘空间是否占满,清理磁盘空间即可
- Java的checked exception与unchecked exception
在Java中exception分为checked exception和unchecked异常,两者有什么区别呢? 从表象来看, checked异常就是需要在代码中try ... catch ...的异 ...
- java中的Checked Exception和Unchecked Exception的区别
Java 定义了两种异常: - Checked exception: 继承自 Exception 类是 checked exception.代码需要处理 API 抛出的 checked excepti ...
- checked exception和unchecked exception区别
http://blog.csdn.net/yuefengyuan/article/details/6204317 一. Java 中定义了两类异常: 1) Checked exception: 这类异 ...
- ckecked Exception和Unchecked Exception异常
Throwable 是所有 Java 程序中错误处理的父类 Error JVM Exception 程序 Checked Exception:继承java.lang.Exception 代表程序不能控 ...
随机推荐
- Oracle查看和修改连接数
1.查询数据库当前进程的连接数: select count(*) from v$process; 2.查看数据库当前会话的连接数: elect count(*) from v$sessio ...
- 给深度学习入门者的Python快速教程
给深度学习入门者的Python快速教程 基础篇 numpy和Matplotlib篇 本篇部分代码的下载地址: https://github.com/frombeijingwithlove/dlcv_f ...
- cento7.3下玩转sphinx
cento7.5下玩转sphinx 1 安装依赖文件 yum install postgresql-libs unixODBC 2 下载 wget http://sphinxsearch.com/fi ...
- 数据分析之Numpy-数组计算
引言 : 数据分析 : 就是把隐藏在一些看似杂乱无章的数据背后的信息提炼出来,总结出研究对象的内在规律 . 数据分析三剑客 : Numpy 数组计算 Pandas 表计算与数据分析 ...
- Keil MDK 和 IAR 两款ARM开发工具区别比较
首先要说明,没有那款开发工具是万能的,也没有那款工具在所有方面都具有绝对优势.对于Keil MDK-ARM和IAR两款工具择,可以根据自己的习惯来选择,而不应该在使用其中的一款时贬低另外一款,或者总是 ...
- sql之分区域分段统计
sql之分区域分段统计 需求:在一个表中,有两列分别标记行政区划代码和家庭成员人数,需要得到不同乡镇的家庭成员人数在1-2人,3-4人,5-6人,6人以上的家庭数的表格 思路: 用case when对 ...
- C#中StreamReader读取中文出现乱码
转自yhrun原文C#中StreamReader读取中文出现乱码 原因是自Windows 2000之后的操作系统在文件处理时默认编码采用Unicode 所以.NET文件的默认编码也是Unicode.除 ...
- leetcode687
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...
- Mysql 日志文件类型
简介: Mysql 中提供了多种类型的日志文件,分别反映 Mysql 的不同信息,了解它们很有必要. 1.Error log ( 错误日志 ) 错误日志记录了 Mysql Server 运行过程中所有 ...
- GitHub个人使用入门
今天突然想起来了github 于是开始了入门之旅 如果你用过svn 那么你用起来感觉入门比较快的(至少我是这么感觉的)和在svn服务器上建项目的流程很像 每次修改代码之后提交的过程是: add, co ...