Namespaces
Variants
Views
Actions

Error numbers

From cppreference.com
< cpp‎ | error
Revision as of 23:33, 12 July 2021 by 111.222.64.111 (Talk)

 
 
 

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
Argument list too long
(macro constant)
EACCES
Permission denied
(macro constant)
EADDRINUSE
Address in use
(macro constant)
EADDRNOTAVAIL
Address not available
(macro constant)
EAFNOSUPPORT
Address family not supported
(macro constant)
EAGAIN
Resource unavailable, try again
(macro constant)
EALREADY
Connection already in progress
(macro constant)
EBADF
Bad file descriptor
(macro constant)
EBADMSG
Bad message
(macro constant)
EBUSY
Device or resource busy
(macro constant)
ECANCELED
Operation canceled
(macro constant)
ECHILD
No child processes
(macro constant)
ECONNABORTED
Connection aborted
(macro constant)
ECONNREFUSED
Connection refused
(macro constant)
ECONNRESET
Connection reset
(macro constant)
EDEADLK
Resource deadlock would occur
(macro constant)
EDESTADDRREQ
Destination address required
(macro constant)
EDOM
Mathematics argument out of domain of function
(macro constant)
EEXIST
File exists
(macro constant)
EFAULT
Bad address
(macro constant)
EFBIG
File too large
(macro constant)
EHOSTUNREACH
Host is unreachable
(macro constant)
EIDRM
Identifier removed
(macro constant)
EILSEQ
Illegal byte sequence
(macro constant)
EINPROGRESS
Operation in progress
(macro constant)
EINTR
Interrupted function
(macro constant)
EINVAL
Invalid argument
(macro constant)
EIO
I/O error
(macro constant)
EISCONN
Socket is connected
(macro constant)
EISDIR
Is a directory
(macro constant)
ELOOP
Too many levels of symbolic links
(macro constant)
EMFILE
File descriptor value too large
(macro constant)
EMLINK
Too many links
(macro constant)
EMSGSIZE
Message too large
(macro constant)
ENAMETOOLONG
Filename too long
(macro constant)
ENETDOWN
Network is down
(macro constant)
ENETRESET
Connection aborted by network
(macro constant)
ENETUNREACH
Network unreachable
(macro constant)
ENFILE
Too many files open in system
(macro constant)
ENOBUFS
No buffer space available
(macro constant)
ENODATA
No message is available on the STREAM head read queue
(macro constant)
ENODEV
No such device
(macro constant)
ENOENT
No such file or directory
(macro constant)
ENOEXEC
Executable file format error
(macro constant)
ENOLCK
No locks available
(macro constant)
ENOLINK
Link has been severed
(macro constant)
ENOMEM
Not enough space
(macro constant)
ENOMSG
No message of the desired type
(macro constant)
ENOPROTOOPT
Protocol not available
(macro constant)
ENOSPC
No space left on device
(macro constant)
ENOSR
No STREAM resources
(macro constant)
ENOSTR
Not a STREAM
(macro constant)
ENOSYS
Function not supported
(macro constant)
ENOTCONN
The socket is not connected
(macro constant)
ENOTDIR
Not a directory
(macro constant)
ENOTEMPTY
Directory not empty
(macro constant)
ENOTRECOVERABLE
State not recoverable
(macro constant)
ENOTSOCK
Not a socket
(macro constant)
ENOTSUP
Not supported
(macro constant)
ENOTTY
Inappropriate I/O control operation
(macro constant)
ENXIO
No such device or address
(macro constant)
EOPNOTSUPP
Operation not supported on socket
(macro constant)
EOVERFLOW
Value too large to be stored in data type
(macro constant)
EOWNERDEAD
Previous owner died
(macro constant)
EPERM
Operation not permitted
(macro constant)
EPIPE
Broken pipe
(macro constant)
EPROTO
Protocol error
(macro constant)
EPROTONOSUPPORT
Protocol not supported
(macro constant)
EPROTOTYPE
Protocol wrong type for socket
(macro constant)
ERANGE
Result too large
(macro constant)
EROFS
Read-only file system
(macro constant)
ESPIPE
Invalid seek
(macro constant)
ESRCH
No such process
(macro constant)
ETIME
Stream ioctl() timeout
(macro constant)
ETIMEDOUT
Connection timed out
(macro constant)
ETXTBSY
Text file busy
(macro constant)
EWOULDBLOCK
Operation would block
(macro constant)
EXDEV
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

#include <cerrno>
#include <clocale>
#include <cmath>
#include <cstring>
#include <iostream>
 
int main()
{
    const 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) [edit]
macro which expands to POSIX-compatible thread-local error number variable
(macro variable)[edit]
displays a character string corresponding of the current error to stderr
(function) [edit]
returns a text version of a given error code
(function) [edit]
C documentation for Error numbers