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. WindowsPhone自定义控件详解(一) - 控件类库分析

    转自:http://blog.csdn.net/mr_raptor/article/details/7251942 为了让你的应用程序更有个性,我们通常会在WP7开发过程中会自定义自己风格的控件,自定 ...

  2. 导入城市文件数据(csv)格式demo

    页面: js: 后台:

  3. Http协议是有状态的还是无状态的???

    在查找session和cookie的区别的资料时,有资料提到http是无状态的.我是不会忘记的,企鹅面试官问过我“http协议是有状态的还是无状态的”,我说不知道(之前没听说过).后来想想那“404 ...

  4. Vue源码(一)

    入口文件 src/core/instance/index.js 中可以看到 function Vue (options) { if (process.env.NODE_ENV !== 'product ...

  5. 用 Sqlmap 识别 WAF

    命令: ┌─[root@sch01ar]─[~] └──╼ #sqlmap -u "http://www.sch01ar.com/" --identify-waf --batch ...

  6. 「小程序JAVA实战」小程序我的个人信息页面开发(41)

    转自:https://idig8.com/2018/09/05/xiaochengxujavashizhanxiaochengxuwodegerenxinxiyemiankaifa40/ 已经完成了登 ...

  7. 解读linux中用户密码规则及忘记root口令的破解(思路)

    linux当中,用户名和密码表对应关系放在/etc/passwd中,如: root:x:0:0:root:/root:/bin/bash 格式代表意义分别为 用户名:密码:用户id:组id:用户描述 ...

  8. vue 起步_code

    <template> <div class="hello"> <h1>{{ msg }}</h1> <div>{{dat ...

  9. 常用sql语句备份

    1.查看数据库中所有的存储过程 use [DataBase_Name] go SELECT * FROM sys.all_objects WHERE ([type] = 'P' OR [type] = ...

  10. iOS学习之自定义弹出UIPickerView或UIDatePicker(动画效果)

    前面iOS学习之UIPickerView控件的简单使用 用到的UIPickerView弹出来是通过 textField.inputView = selectPicker;   textField.in ...