Error code: Difference between revisions

Content deleted Content added
intro
m fix broken link
Line 9:
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 [[thread (computer science} )| multithreaded]] environment, since the process global variables could be set by more than one thread, causing a [[race condition]].
 
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.