Error numbers
From cppreference.com
Each of the macros defined in <cerrno>
expands to integer constant expressions with type int, each with a positive value, matching most of the POSIX error codes. The following constants are defined (the implementation may define more, as long as they begin with 'E' followed by digits or uppercase letters)
Defined in header
<cerrno> | |
E2BIG (C++11) |
Argument list too long (macro constant) |
EACCES (C++11) |
Permission denied (macro constant) |
EADDRINUSE (C++11) |
Address in use (macro constant) |
EADDRNOTAVAIL (C++11) |
Address not available (macro constant) |
EAFNOSUPPORT (C++11) |
Address family not supported (macro constant) |
EAGAIN (C++11) |
Resource unavailable, try again (macro constant) |
EALREADY (C++11) |
Connection already in progress (macro constant) |
EBADF (C++11) |
Bad file descriptor (macro constant) |
EBADMSG (C++11) |
Bad message (macro constant) |
EBUSY (C++11) |
Device or resource busy (macro constant) |
ECANCELED (C++11) |
Operation canceled (macro constant) |
ECHILD (C++11) |
No child processes (macro constant) |
ECONNABORTED (C++11) |
Connection aborted (macro constant) |
ECONNREFUSED (C++11) |
Connection refused (macro constant) |
ECONNRESET (C++11) |
Connection reset (macro constant) |
EDEADLK (C++11) |
Resource deadlock would occur (macro constant) |
EDESTADDRREQ (C++11) |
Destination address required (macro constant) |
EDOM |
Mathematics argument out of domain of function (macro constant) |
EEXIST (C++11) |
File exists (macro constant) |
EFAULT (C++11) |
Bad address (macro constant) |
EFBIG (C++11) |
File too large (macro constant) |
EHOSTUNREACH (C++11) |
Host is unreachable (macro constant) |
EIDRM (C++11) |
Identifier removed (macro constant) |
EILSEQ (C++11) |
Illegal byte sequence (macro constant) |
EINPROGRESS (C++11) |
Operation in progress (macro constant) |
EINTR (C++11) |
Interrupted function (macro constant) |
EINVAL (C++11) |
Invalid argument (macro constant) |
EIO (C++11) |
I/O error (macro constant) |
EISCONN (C++11) |
Socket is connected (macro constant) |
EISDIR (C++11) |
Is a directory (macro constant) |
ELOOP (C++11) |
Too many levels of symbolic links (macro constant) |
EMFILE (C++11) |
File descriptor value too large (macro constant) |
EMLINK (C++11) |
Too many links (macro constant) |
EMSGSIZE (C++11) |
Message too large (macro constant) |
ENAMETOOLONG (C++11) |
Filename too long (macro constant) |
ENETDOWN (C++11) |
Network is down (macro constant) |
ENETRESET (C++11) |
Connection aborted by network (macro constant) |
ENETUNREACH (C++11) |
Network unreachable (macro constant) |
ENFILE (C++11) |
Too many files open in system (macro constant) |
ENOBUFS (C++11) |
No buffer space available (macro constant) |
ENODATA (C++11) |
No message is available on the STREAM head read queue (macro constant) |
ENODEV (C++11) |
No such device (macro constant) |
ENOENT (C++11) |
No such file or directory (macro constant) |
ENOEXEC (C++11) |
Executable file format error (macro constant) |
ENOLCK (C++11) |
No locks available (macro constant) |
ENOLINK (C++11) |
Link has been severed (macro constant) |
ENOMEM (C++11) |
Not enough space (macro constant) |
ENOMSG (C++11) |
No message of the desired type (macro constant) |
ENOPROTOOPT (C++11) |
Protocol not available (macro constant) |
ENOSPC (C++11) |
No space left on device (macro constant) |
ENOSR (C++11) |
No STREAM resources (macro constant) |
ENOSTR (C++11) |
Not a STREAM (macro constant) |
ENOSYS (C++11) |
Function not supported (macro constant) |
ENOTCONN (C++11) |
The socket is not connected (macro constant) |
ENOTDIR (C++11) |
Not a directory (macro constant) |
ENOTEMPTY (C++11) |
Directory not empty (macro constant) |
ENOTRECOVERABLE (C++11) |
State not recoverable (macro constant) |
ENOTSOCK (C++11) |
Not a socket (macro constant) |
ENOTSUP (C++11) |
Not supported (macro constant) |
ENOTTY (C++11) |
Inappropriate I/O control operation (macro constant) |
ENXIO (C++11) |
No such device or address (macro constant) |
EOPNOTSUPP (C++11) |
Operation not supported on socket (macro constant) |
EOVERFLOW (C++11) |
Value too large to be stored in data type (macro constant) |
EOWNERDEAD (C++11) |
Previous owner died (macro constant) |
EPERM (C++11) |
Operation not permitted (macro constant) |
EPIPE (C++11) |
Broken pipe (macro constant) |
EPROTO (C++11) |
Protocol error (macro constant) |
EPROTONOSUPPORT (C++11) |
Protocol not supported (macro constant) |
EPROTOTYPE (C++11) |
Protocol wrong type for socket (macro constant) |
ERANGE |
Result too large (macro constant) |
EROFS (C++11) |
Read-only file system (macro constant) |
ESPIPE (C++11) |
Invalid seek (macro constant) |
ESRCH (C++11) |
No such process (macro constant) |
ETIME (C++11) |
Stream ioctl() timeout (macro constant) |
ETIMEDOUT (C++11) |
Connection timed out (macro constant) |
ETXTBSY (C++11) |
Text file busy (macro constant) |
EWOULDBLOCK (C++11) |
Operation would block (macro constant) |
EXDEV (C++11) |
Cross-device link (macro constant) |
All values are required to be unique except that the values of EOPNOTSUPP
and ENOTSUP
may be identical and the values of EAGAIN
and EWOULDBLOCK
may be identical
Example
Run this code
#include <iostream> #include <cmath> #include <cerrno> #include <cstring> #include <clocale> int main() { double not_a_number = std::log(-1.0); std::cout << not_a_number << '\n'; 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:
nan log(-1) failed: Numerical argument out of domain Or, in German, Das numerische Argument ist ausserhalb des Definitionsbereiches
See also
(C++11) |
the std::error_condition enumeration listing all standard <cerrno> macro constants (class) |
macro which expands to POSIX-compatible thread-local error number variable (macro variable) | |
displays a character string corresponding of the current error to stderr (function) | |
returns a text version of a given error code (function) |