zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    上传并压缩图片
    C#使用一般处理程序(ashx)中session
    cookie记住用户名密码
    操作数组
    鼠标滚轮事件兼容写法
    table嵌套table,jquery获取tr个数
    网站性能调优实战-学相伴KuangStudy
    为什么fdisk分区第一个分区以63或者2048扇区开始?
    oracle分组查询,获取组内所有信息(拼接显式)
    oracle中对象类型搜集(object type)
  • 原文地址:https://www.cnblogs.com/zno2/p/4580133.html
Copyright © 2011-2022 走看看