Content deleted Content added
Erkan Yilmaz (talk | contribs) |
|||
Line 2:
==Examples==
In programming languages without [[structured exception handling]] (e.g. in the [[C (programming language)|C programming language]]), ''error codes'' are often stored in [[global variable]]s with names like <code>errno</code>. Error codes are typically identified by number, each indicating a specific error condition. In an application that uses error codes, each function typically defines one ''return code'' to indicate a general failure. Upon receipt of that general failure return code, the programmer can check the value stored in the global error code to determine the condition that caused the function to fail. For example, to indicate that an attempt to open a file failed, a function may set the global error code to indicate the cause of the failure and return an invalid file handle. The following sample shows how the error code can be used to explain the cause of the error:
Line 14 ⟶ 13:
==Error codes and exception handling==
Error codes are slowly disappearing from the programmer's environment as modern [[object oriented]] [[computer languages]] replace them with [[exceptions]]. Exceptions have the advantage of being handled with explicit blocks of code, separate from the rest of the code. While it is considered poor practice in methodologies that use error codes and return codes to indicate failure, programmers often neglect to check return values for error conditions. That negligence can cause undesirable effects, as ignored error conditions often cause more severe problems later in the program. Exceptions are implemented in such a way as to separate the error handling code from the rest of the code. Separating the error handling code from the normal logic makes programs easier to write and understand, since one block of error handling code can service errors from any number of function calls. Exception handling also makes the code more readable than implementations with error codes, since exception handling does not disrupt the flow of the code with frequent checks for error conditions.
==See also==
*[[Abort (computing)]]
*[[Aspect-oriented programming]]
*[[Failure]]
*[[Static code analysis]]
==External links==
*Article "[http://www-128.ibm.com/developerworks/aix/library/au-errnovariable/index.html Errors: errno in UNIX programs]" by [[Chris Herborth]]
*Article "[http://www.on-time.com/ddj0011.htm Exception Handling in C without C++]" by [[Tom Schotland]] and [[Peter Petersen]]
*Article "[http://damienkatz.net/2006/04/error_code_vs_e.html Error codes or Exceptions? Why is Reliable Software so Hard?]" by [[Damien Katz]]
*[http://msdn2.microsoft.com/en-us/library/ms679321.aspx Win32 Error Handling Functions]
[[Category:Debugging]]
[[Category:Computer errors]]
[[Category:
[[de:Fehlercode]]
|