< cpp‎ | error
Revision as of 15:50, 2 November 2012 by P12bot (Talk | contribs)


Template:ddcl list begin <tr class="t-dsc-header">

Defined in header <cerrno>

<td></td> <td></td> <tr class="t-dcl ">

<td class="t-dcl-nopad">
#define errno /*implementation-defined*/

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

errno is a preprocessor macro that expands to a static(until C++11) / thread-local(since C++11) modifiable lvalue of type int. Several standard library functions indicate errors by writing positive integers to errno. Typically, the value of errno is set to one of the error codes, listed in <cerrno> as macro constants that begin with the letter E, followed by uppercase letters or digits.

The value of errno is 0 at program startup, and although library functions are allowed to write positive integers to errno whether or not an error occurred, library functions never store 0 in errno.


#include <iostream>
#include <cmath>
#include <cerrno>
#include <cstring>
#include <clocale>
int main()
    double not_a_number = std::log(-1.0);
    if (errno == EDOM) {
        std::cout << "log(-1) failed: " << std::strerror(errno) << '\n';
        std::setlocale(LC_MESSAGES, "de_DE.utf8");
        std::cout << "Or, in German, " << std::strerror(errno) << '\n';

Possible output:

log(-1) failed: Numerical argument out of domain
Or, in German, Das numerische Argument ist ausserhalb des Definitionsbereiches

See also

Template:cpp/error/dcl list errno macrosTemplate:cpp/io/c/dcl list perrorTemplate:cpp/string/byte/dcl list strerror