Error code
From Wikipedia, the free encyclopedia
In computer programming, error codes are enumerated messages that correspond to faults in a specific software application. They are typically used to identify faulty hardware, software, or incorrect user input in programming languages that lack exception handling, although they are sometimes also be used in conjunction with exception handling. Error codes are not to be confused with return codes, although both are commonly used together in error handling. Some of the most severe error codes visible to users are the "Blue Screen of Death" codes provided by the Microsoft Windows operating systems.
Contents |
[edit] 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.
[edit] A common coding error
If you're trying to run a fairly old program on systems with a recent libc, you can encounter the following situations depending on the version :
- The program runs but gives a warning
Incorrectly built binary which accesses errno or h_errno directly. Needs to be fixed.
- The program does not run giving error
symbol errno, version GLIBC_2.0 not defined in file libc.so.6 with link time reference
errno is defined by the ISO C standard to be a modifiable lvalue of type int, and must not be explicitly declared. It was common in traditional C to declare errno manually (i.e., extern int errno) instead of including <errno.h>. It will not work with modern versions of the C library. However, on (very) old Unix systems, there may be no <errno.h> and the declaration is needed.
In such situations, the source code must be modified to replace all extern int errno lines with a single include:
#include <errno.h>

