青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

sherrylso

C++博客 首頁 新隨筆 聯系 聚合 管理
  18 Posts :: 0 Stories :: 124 Comments :: 0 Trackbacks
不知道大家是否有同感,在開發軟件應用系統的過程中我們經常面臨一個非常tedious的問題,即如何分類和處理軟件行為產生的錯誤值,大致有這樣幾個方面的問題:
        第一.錯誤值如何分類。參考microsoft的開放文檔,按照錯誤值的嚴重程度分為critical、error、warning、information等四個級別。
        第二.錯誤值如何在各個軟件子模塊中有效的表示和溝通。
        第三.如何劃分出用戶所關心的錯誤值集合。
這篇文章對錯誤類型定義與處理作了很好的闡釋。推薦給大家,大家如果有什么好的開發經驗,歡迎探討。
FYI:
Taxonomy of Error Types and Error Handling
Posted: Jun 21, 2007 8:13 PM

Most of what is written about error and exception handling is fairly abstract and vague. When specific recommendations are made, those usually consist of examples given for specific circumstances. Yet, error handling is a fundamental task for developers. This brief review attempts to categorize the different types of error conditions a program can encounter. By describing these categories, I also provide suggestions on how to handle each type of error condition.

In general, errors a program can encounter tend to be the result of one of three things:

  • Restrictions: Arguments to a routine that can never work, and always result in an error, define a restriction on the use of the routine. Ensuring that only correct arguments are passed to a routine is the type of thing that programming by contract is meant to address.
  • Inconsistencies: When values or resources are not what they are expected to be, or are missing, that creates an inconsistency between the expected state of the environment and the actual state. This may be the internal environment, such as a null pointer, or the external environment, such as a corrupt file. It doesn't encompass inconsistencies in the data model, which often needs to be temporarily inconsistent during an operation (e.g. adding a node to a linked list).
  • Failures When an operation simply does not work, and it's out of the program's control, this is a failure. For example, a pulled network cable.

These types of errors overlap to an extent (say, a working network could be considered part of the expected state, making it an inconsistency error). In general, though, most errors can fall into one of these categories.

Sometimes failures are not errors, and are just a way of detecting the current external state. For example, opening a file that doesn't exist may fail, but results in an error only when that file is actually needed.

Error Handling Responsibilities

Program code is responsible for the consistency of the internal program state. Generally certain code has primary (ideally, exclusive) responsibility for parts of the internal state. Inconsistency errors that occur within the code responsible for that state are bugs.

Sometimes the state management responsibility is shared between different sections of code. This is a bad idea, because it makes assigning responsibility for an inconsistency error harder, but it does happen in practice.

It's important to make a distinction between error detection and debugging. Often, data generated in the process of error handling is mixed together with diagnostic information. If possible, these types of information should be kept completely separate—at least conceptually, even if combined in a single data structure.

Safe Zones

Restrictions can be checked before calling a routine, or within a routine. It seems a waste of time to check arguments every time a routine is called when you already know those arguments are correct. One strategy is to separate parameter checking from parameter usage. This doesn't work reliably for library code, where anything can happen between the check and the use of the parameters, but within a base of code for a particular application or within a library, you can restrict the code to not change a value known to be safe.

The code between a parameter check and the next change to a parameter variable is a safe zone, where parameters don't have to be re-checked. This is only valid for restriction errors, because inconsistency and failure errors can be caused by things outside the code's safe zone. Things like critical sections (in multithreaded environments), semaphores and file locks are meant to create a very limited kind of safe zone for inconsistency and failure errors.

The code safe zones for parameters can overlap with others, and may not be well defined. One way to deal with this is to assign known safe values to variables which indicate this safety. Joel Spolsky wrote about one way to do this using variable naming conventions in Making Wrong Code Look Wrong. Safe values should be assigned to variables declared constant.

Reporting Errors

Code calling a routine needs to know three things to decide how to proceed: First, whether the data is returned, if any, or if the method invocation succeeded; second, whether an error occurred; and, third, whether the error is permanent or transitory. This defines the following possible error states returned from a routine:

  1. Successful
  2. Restriction error (always permanent)
  3. Permanent (bug) inconsistency
  4. Transitory (detected) inconsistency
  5. Failure (transitory for all we know)

It's often a bad idea to mix an error code with a return value, such as designating a specific values—say, 0 or -1—to be invalid. Some languages, like Python, allow multiple values to be returned from a method as tuples. A tuple is basically an anonymous class, and can be implemented in a language like Java by defining a class for objects returned by a method, or in C by defining a struct which is passed as a parameter and is updated by the function. But in many cases, exceptions are a much better way to separate error information from return values.

Exceptions transmit an object from the exception location to a handler in a scope surrounding it, or surrounding the point where the routine was called. The exception objects include information by the object type and class, and debugging information the data contained within that type. Exceptions by themselves don't indicate the error state, so that must be included as an attribute of the exception object, or the error state must be deduced from the debugging information (object type and data).

Java introduced the controversial notion of checked exceptions, which must either be caught or declared to be thrown by a method in order to compile, while unchecked (or runtime) exceptions behave like exceptions in other languages. The main cause of the controversy is that there has been no good definition of why there should be a difference and, as a result, no consistent strategy in the implementation in various libraries, including standard parts of the different Java runtime libraries.

In general, unchecked exceptions are meant for bugs, where an error indicates that the code is simply wrong and must be fixed (restriction and bug inconsistency errors). An example is a NullPointerException. Checked exceptions are for detected inconsistency and failure errors, where the program may have a strategy of handling the error. An example is an I/O error.

Transactional Operations

One strategy to handle errors is to make all operations transactional, so that if they fail, it's as if the operation was never tried. One way implement this is to define an "undo" operation for every change:

Ideal transactional function

In this example, the functions are also transactional, and thus don't need to be rolled back if they fail. This can be done with nested if/else blocks, or with nested try/catch blocks. If the "undo" operations themselves have errors, the result looks more like this:

Realistic transactional function

One way of dealing with this is to modify a copy of the program state, and if all operations succeed, only then commit the changes. The commit may fail, but this isolates the possible state changing errors to one point, and is similar how databases implement transactions. Another way to implement transactional operations is to make a copy of before any state is changed, and use that copy to restore the expected state, in case of an error.

In summary, having a clear taxonomy of error conditions that code may encounter helps develop better strategies for dealing with, and possibly recovering from, those errors.

posted on 2007-07-15 18:31 愛上龍卷風 閱讀(1141) 評論(0)  編輯 收藏 引用
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美在线资源| 精品二区久久| 在线一区二区三区四区五区| 亚洲高清在线| 亚洲电影成人| 欧美成人亚洲成人| 亚洲电影毛片| 亚洲人成亚洲人成在线观看图片| 久久久久国产一区二区三区四区| 午夜亚洲一区| 久久久国产精品一区二区三区| 午夜国产精品影院在线观看| 午夜久久久久久| 久久视频在线免费观看| 欧美在线视频观看| 久久中文字幕一区二区三区| 免费观看成人鲁鲁鲁鲁鲁视频| 久久野战av| 亚洲激情不卡| 午夜一区不卡| 欧美另类极品videosbest最新版本 | 性8sex亚洲区入口| 久久青草福利网站| 亚洲国产毛片完整版| 亚洲视频999| 久久久久久九九九九| 欧美日韩视频| 在线不卡欧美| 亚洲欧美日本国产有色| 女人色偷偷aa久久天堂| 这里是久久伊人| 欧美承认网站| 韩国成人理伦片免费播放| 久久狠狠亚洲综合| 麻豆91精品| 国产情侣一区| 亚洲久久成人| 美女免费视频一区| 亚洲小说春色综合另类电影| 牛牛精品成人免费视频| 国内精品久久久久久久影视麻豆| 日韩视频在线免费观看| 久久综合伊人77777蜜臀| 日韩图片一区| 久久久久国产精品麻豆ai换脸| 国产精品二区三区四区| 亚洲人午夜精品免费| 久久精品成人一区二区三区| 99精品视频免费观看视频| 欧美高清在线视频| 亚洲黄网站在线观看| 嫩草国产精品入口| 欧美一区影院| 国产老女人精品毛片久久| 亚洲女人天堂av| 亚洲精品久久久久久下一站| 久久免费国产精品1| 国产精品福利av| 亚洲欧美变态国产另类| 亚洲精品国久久99热| 麻豆成人精品| 国模大胆一区二区三区| 欧美一级理论片| 一本色道久久综合精品竹菊| 欧美精品免费看| ●精品国产综合乱码久久久久| 久久精品视频免费| 亚洲欧美一区二区精品久久久| 欧美激情精品久久久久久久变态| 亚洲国产精品va在看黑人| 久久久久久亚洲精品杨幂换脸 | 久久成人综合网| 国产一级一区二区| 老牛嫩草一区二区三区日本| 久久久天天操| 日韩午夜三级在线| 日韩视频在线观看免费| 欧美日韩在线观看一区二区| 亚洲综合色婷婷| 欧美亚洲在线观看| 国内伊人久久久久久网站视频| 老司机午夜精品视频在线观看| 老司机亚洲精品| 一本久久青青| 欧美一区二区网站| 亚洲精品一二| 亚洲免费视频一区二区| 在线成人激情黄色| 亚洲另类春色国产| 国产乱码精品一区二区三区av | 国产精品色在线| 国产女主播在线一区二区| 久久精品在线免费观看| 久久影视三级福利片| 9人人澡人人爽人人精品| 亚洲性夜色噜噜噜7777| 在线观看一区二区视频| 一区二区三区欧美亚洲| 黄色成人在线观看| 亚洲人成绝费网站色www| 国产精品亚洲不卡a| 欧美风情在线| 国产精品日韩一区二区三区| 牛夜精品久久久久久久99黑人 | 亚洲视频axxx| 久久精品夜夜夜夜久久| 99视频精品在线| 久久九九久精品国产免费直播 | 亚洲一区二区免费视频| 久久精品女人天堂| 亚洲欧美清纯在线制服| 欧美激情性爽国产精品17p| 久久米奇亚洲| 国产精品日韩在线播放| 99re8这里有精品热视频免费| 尤物99国产成人精品视频| 亚洲小说欧美另类婷婷| 夜夜精品视频一区二区| 蜜臀va亚洲va欧美va天堂 | 99综合在线| 老牛嫩草一区二区三区日本| 性亚洲最疯狂xxxx高清| 欧美日韩国产页| 亚洲国产高清在线| 亚洲国产cao| 久久青青草原一区二区| 久久国产精品一区二区| 国产精品久久福利| 99国产精品久久久久老师| 日韩网站免费观看| 欧美激情视频一区二区三区免费| 欧美成人高清视频| 久久国产精品一区二区三区| 亚洲综合999| 国产精品jizz在线观看美国| 亚洲欧洲一区二区天堂久久| 亚洲精品久久久久久久久| 久久五月婷婷丁香社区| 久久视频精品在线| 国产欧美在线观看| 性欧美激情精品| 久久成人精品无人区| 国产啪精品视频| 欧美伊人久久久久久久久影院| 午夜精品福利一区二区蜜股av| 欧美日韩另类在线| 亚洲精品国精品久久99热一| 一区二区三区视频在线看| 欧美视频四区| 亚洲一区欧美激情| 国产精品久久久久久久久久久久| 亚洲欧美成人一区二区三区| 国产精品99一区二区| 国产精品99久久99久久久二8| 亚洲免费视频成人| 国产精品一区二区欧美| 欧美一区二区三区精品电影| 麻豆亚洲精品| 日韩亚洲一区二区| 国产精品剧情在线亚洲| 久久精品国产亚洲aⅴ| 欧美激情aⅴ一区二区三区| 一区二区91| 国产自产精品| 欧美国产专区| 午夜精品久久久久| 老司机67194精品线观看| 亚洲国内自拍| 国产精品美女久久久久久2018| 欧美一级黄色录像| 亚洲国产精品一区| 欧美一区激情| 亚洲清纯自拍| 国产精品欧美在线| 欧美二区在线播放| 欧美一区二区三区四区夜夜大片| 欧美成人高清| 欧美一区二区三区四区高清| 亚洲欧洲日产国码二区| 国产精品亚洲美女av网站| 嫩草伊人久久精品少妇av杨幂| 亚洲视频碰碰| 最新国产成人av网站网址麻豆| 欧美一区二区三区在线看| 亚洲人成毛片在线播放| 国产欧美日韩亚洲精品| 欧美精品一区视频| 免费美女久久99| 欧美一区二区精品久久911| 亚洲激情视频在线播放| 久久躁狠狠躁夜夜爽| 欧美一级视频精品观看| 99ri日韩精品视频| 亚洲第一区中文99精品| 国产一区在线看| 国产精品欧美日韩久久| 欧美日韩一区二区高清| 欧美va亚洲va国产综合| 久久久蜜桃一区二区人| 午夜精品视频|