Error code: Difference between revisions

Content deleted Content added
"translated to English" some of the computerese, added example source of errno, more info on errno.
clarify
Line 1:
In [[Programming language|computer programming]], '''error codes''' are numberedenumerated messages that correspond to faults in a specific [[software application]],. whichThey canare betypically causedused to byidentify faulty [[hardware]], [[software]], or incorrect user input in programming languages that lack [[exception handling]]. '''Error codes''' are not to be confused with [[return code|return codes]]s, thoughalthough the latterboth are commonly used together in error handling. Some of the most commonsevere error codes visible to users are the "[[Blue Screen of Death]]" codes provided by the [[Microsoft Windows]] [[operating system]].
 
ErrorIn codesprogramming arelanguages oftenwithout [[processstructured exception handling (computing)e.g. |in processthe [[C programming language]]), ''error codes'' are often stored in [[global variable]]s, suchwith asnames like ''errno'' in. theError [[Ccodes programmingare language]].typically identified Aby returnnumber, codeeach fromindicating a function will indicate anspecific error condition. In andan theapplication programmerthat canuses thenerror checkcodes, theeach valuefunction oftypically defines one ''errnoreturn code'', whichto isindicate visiblea fromgeneral anywherefailure. inUpon thereceipt programof that general failure return code, againstthe aprogrammer listcan ofcheck possiblethe errorsvalue stored in the global error code to determine whythe condition that caused the function callto failedfail. AnFor example, ofto thisindicate wouldthat be aan callattempt to open a file; iffailed, thea filefunction handlemay returnedset isthe notglobal valid,error then errno can be examinedcode to determineindicate the cause of the failure. and return an invalid file handle. The following sample shows how the error code in errno can be used to return an error string explainingexplain the cause of the error:
 
/* attempt to open file for reading */
Line 9:
printf("Cannot open file, error %i, %s\n", errno, strerror(errno));
 
Since the error codecodes inare this case is atypically global variablevariables, itthey can be read or written from any portion of the program. As with other global variables, andthat ease of thisaccess 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 failneglect to check return values for error conditions,. andThat thisnegligence can cause undesirable effects, as ignored error codesconditions often cause additionalmore 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 itexception handling does not disrupt the flow of the code with frequent checks for error conditions.
 
[[Category:Programming bugs]]