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的更多相关文章

  1. Exception (2) Java Exception Handling

    The Java programming language uses exceptions to handle errors and other exceptional events.An excep ...

  2. Exception (3) Java exception handling best practices

    List Never swallow the exception in catch block Declare the specific checked exceptions that your me ...

  3. Checked Exception与Runtime Exception 的区别

    Java里有个很重要的特色是Exception ,也就是说允许程序产生例外状况.而在学Java 的时候,我们也只知道Exception 的写法,却未必真能了解不同种类的Exception 的区别. 首 ...

  4. vagrant yii2 Exception 'yii\db\Exception' with message 'SQLSTATE[HY000] [2002]

    开发环境:vangrant + LAMP 安装了yii2 advanced版本之后,通过url访问fornted 报数据库user表不存在,看了安装yii2 advanced的教程,里面说需要需要运行 ...

  5. jenkins编辑报错Exception when publishing, exception message的解决办法

    jenkins编辑报错Exception when publishing, exception message的解决办法 查看目标主机的磁盘空间是否占满,清理磁盘空间即可

  6. Java的checked exception与unchecked exception

    在Java中exception分为checked exception和unchecked异常,两者有什么区别呢? 从表象来看, checked异常就是需要在代码中try ... catch ...的异 ...

  7. java中的Checked Exception和Unchecked Exception的区别

    Java 定义了两种异常: - Checked exception: 继承自 Exception 类是 checked exception.代码需要处理 API 抛出的 checked excepti ...

  8. checked exception和unchecked exception区别

    http://blog.csdn.net/yuefengyuan/article/details/6204317 一. Java 中定义了两类异常: 1) Checked exception: 这类异 ...

  9. ckecked Exception和Unchecked Exception异常

    Throwable 是所有 Java 程序中错误处理的父类 Error JVM Exception 程序 Checked Exception:继承java.lang.Exception 代表程序不能控 ...

随机推荐

  1. 【UVA】10935 Throwing cards away I(STL队列)

    题目 题目     分析 练习STL     代码 #include <bits/stdc++.h> using namespace std; int main() { int n; wh ...

  2. CEF3中js调用delphi内部方法

    2015-01-20修改:以下方法不适合delphi7,在CEF3源码中限制了delphi_14 up,对于被我误导的朋友说声抱歉 在CEF1中JS调用delphi的方法已经贴过:http://www ...

  3. java类继承总结一 父类类型与子类类型之间的转化问题(转)

    java类继承总结一 父类类型与子类类型之间的转化问题 本文将通过一个实例描述父类类型与子类类型之间的转化问题,这个很特殊的问题常常会导致一些潜在的危险,让你整整一个晚上都在调试程序以解决一个让人抓狂 ...

  4. RMI原理及简单demo

    1 简介 RMI是远程方法调用的简称,它能够帮助我们查找并执行远程对象的方法.通俗地说,远程调用就象将一个class放在A机器上,然后在B机器中调用这个class的方法. 2 概念 其他机器需要调用的 ...

  5. Promise题目

    setTimeout(function () { console.log(1); }, 0) new Promise(function executor(resolve) { console.log( ...

  6. 第二章:Android Studio概述(二)[学习Android Studio汉化教程]

    The Main Menu Bar 主菜单栏  主菜单栏位于Android Studio的最上面,你几乎可以利用主菜单和其子菜单来执行任何操作.不像Android Studio中其他的一些菜单,主菜单 ...

  7. oracle查看登录到oracle服务器的客户端ip

    1. 在sys模式下创建一个表,用于记录客户端登录数据库服务器的详细信息. 1 create table login_history 2 ( 3 username varchar2(60), --用户 ...

  8. centos7.3查看时区

    [root@iZ2ze3gf6h0zndx5dxyhqiZ ~]# date -R Fri, Apr :: + 即可查看时区 我们国家的东八区(+0800) 查看clock系统配置文件 [root@i ...

  9. Arduino UNO 键盘记录器中时钟接到2口或3口,其它接口不行。马上就要放弃了。要修改例子中时钟的引脚。

  10. leetcode844

    class Solution { public: bool backspaceCompare(string S, string T) { stack<char> ST1; ; i < ...