Information about Error Code

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.

Examples

In programming languages without structured exception handling (e.g. in the C programming language), error codes are often stored in global variables with names like errno. 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:

/* attempt to open file for reading */ FILE *fp = fopen("filename", "r"); /* if file cannot be opened, print error number and error string */ if(fp == NULL) printf("Cannot open file, error %i, %s\n", errno, strerror(errno));

Since error codes are typically global variables, they can be read or written from any portion of the program. As with other global variables, that ease of access can be a source of problems in a multithreaded environment, since the process global variables could be set by more than one thread, causing a race condition. To fix this problem, POSIX defines errno to be a thread-local variable.

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.

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>.

See also

External links

A programming language is an artificial language that can be used to control the behavior of a machine, particularly a computer. Programming languages, like natural languagess, are defined by syntactic and semantic rules which describe their structure and meaning respectively.
..... Click the link for more information.
Application software is a subclass of computer software that employs the capabilities of a computer directly and thoroughly to a task that the user wishes to perform. This should be contrasted with system software which is involved in integrating a computer's various capabilities,
..... Click the link for more information.
Hardware is a general term that refers to the physical artifacts of a technology.It may also mean the physical components of a computer system.

Hardware historically meant the metal parts and fittings that were used to make wooden products stronger, more functional, longer
..... Click the link for more information.
Computer software is a general term used to describe a collection of computer programs, procedures and documentation that perform some task on a computer system. [1]
..... Click the link for more information.
Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of some condition that changes the normal flow of execution. The condition is called an exception.
..... Click the link for more information.
Blue Screen of Death (also known as a stop error, BSOD or bluescreen) is an error screen displayed by certain operating systems, most notably Microsoft Windows, after encountering a critical system error.
..... Click the link for more information.
Microsoft Windows

Screenshot of Windows Vista Ultimate, the latest version of Microsoft Windows.
Company/developer: Microsoft Corporation
OS family: MS-DOS/9x-based, Windows CE, Windows NT
Source model: Closed source

..... Click the link for more information.
Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of some condition that changes the normal flow of execution. The condition is called an exception.
..... Click the link for more information.
C

The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language.
..... Click the link for more information.
In computer programming, a global variable is a variable that is accessible in every scope. Interaction mechanism with global variables are called global environment (see also global state) mechanisms.
..... Click the link for more information.
thread in computer science is short for a thread of execution. Threads are a way for a program to fork (or split) itself into two or more simultaneously (or pseudo-simultaneously) running tasks.
..... Click the link for more information.
A race condition or race hazard is a flaw in a system or process whereby the output of the process is unexpectedly and critically dependent on the sequence or timing of other events.
..... Click the link for more information.
POSIX (IPA: /ˈpɒsɪks/) or "Portable Operating System Interface" [1] is the collective name of a family of related standards specified by the IEEE to define the application programming interface (API) for
..... Click the link for more information.
In computer programming, thread-local storage (TLS) is static or global memory local to a thread.

This is sometimes needed because all threads in a process share the same address space.
..... Click the link for more information.
Object-oriented programming (OOP) is a programming paradigm that uses "objects" and their interactions to design applications and computer programs. It is based on several techniques, including inheritance, modularity, polymorphism, and encapsulation.
..... Click the link for more information.
The term computer language includes a wide variety of languages used to communicate with computers. It is broader than the more commonly-used term programming language. Programming languages are a subset of computer languages.
..... Click the link for more information.
Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of some condition that changes the normal flow of execution. The condition is called an exception.
..... Click the link for more information.
The C standard library is a now-standardized collection of header files and library routines used to implement common operations, such as input/output and string handling, in the C programming language.
..... Click the link for more information.
C

The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language.
..... Click the link for more information.
In computer science, a value is a sequence of bits that is interpreted according to some data type. It is possible for the same sequence of bits to have different values, depending on the type used to interpret its meaning.
..... Click the link for more information.
In computer science, the term integer is used to refer to any data type which represents some subset of the mathematical integers. These are also known as integral data types.
..... Click the link for more information.
In a computer or data transmission system, to abort means to terminate , usually in a controlled manner, a processing activity because it is impossible or undesirable for the activity to proceed. Such an action may be accompanied by diagnostic information on the aborted process.
..... Click the link for more information.
In software engineering, the programming paradigms of aspect-oriented programming (AOP), and aspect-oriented software development (AOSD) attempt to aid programmers in the separation of concerns, specifically cross-cutting concerns, as an advance in
..... Click the link for more information.
Editing of this page by unregistered or newly registered users is currently disabled due to vandalism.
If you are prevented from editing this page, and you wish to make a change, please discuss changes on the talk page, request unprotection, log in, or .
..... Click the link for more information.
Static code analysis is the analysis of computer software that is performed without actually executing programs built from that software (analysis performed on executing programs is known as dynamic analysis).
..... Click the link for more information.


This article is copied from an article on Wikipedia.org - the free encyclopedia created and edited by online user community. The text was not checked or edited by anyone on our staff. Although the vast majority of the wikipedia encyclopedia articles provide accurate and timely information please do not assume the accuracy of any particular article. This article is distributed under the terms of GNU Free Documentation License.
Herod_Archelaus


page counter