错误号
来自cppreference.com
定义于 <cerrno> 的每个宏均展开成 int 类型的整数常量表达式,每个都拥有正值,匹配 POSIX 错误码中的大多数。下列常量得到定义(实现可以定义更多,只要它们以 'E' 开始,后随数字或大写字母)
在标头
<cerrno> 定义 | |
E2BIG (C++11) |
参数列表过长 (宏常量) |
EACCES (C++11) |
权限被禁止 (宏常量) |
EADDRINUSE (C++11) |
地址在使用中 (宏常量) |
EADDRNOTAVAIL (C++11) |
地址不可用 (宏常量) |
EAFNOSUPPORT (C++11) |
不支持地址系列 (宏常量) |
EAGAIN (C++11) |
资源不可用,须重试 (宏常量) |
EALREADY (C++11) |
连接已在进行 (宏常量) |
EBADF (C++11) |
坏的的文件描述符 (宏常量) |
EBADMSG (C++11) |
坏的消息 (宏常量) |
EBUSY (C++11) |
设备或资源忙 (宏常量) |
ECANCELED (C++11) |
操作取消 (宏常量) |
ECHILD (C++11) |
无子进程 (宏常量) |
ECONNABORTED (C++11) |
连接被打断 (宏常量) |
ECONNREFUSED (C++11) |
连接被拒绝 (宏常量) |
ECONNRESET (C++11) |
连接被重置 (宏常量) |
EDEADLK (C++11) |
资源死锁会发生 (宏常量) |
EDESTADDRREQ (C++11) |
要求目标地址 (宏常量) |
EDOM |
数学参数在函数定义域外 (宏常量) |
EEXIST (C++11) |
文件已存在 (宏常量) |
EFAULT (C++11) |
坏的地址 (宏常量) |
EFBIG (C++11) |
文件过大 (宏常量) |
EHOSTUNREACH (C++11) |
主机不可抵达 (宏常量) |
EIDRM (C++11) |
标识符被移除 (宏常量) |
EILSEQ (C++11) |
非法字节序列 (宏常量) |
EINPROGRESS (C++11) |
操作已在进行 (宏常量) |
EINTR (C++11) |
函数被中断 (宏常量) |
EINVAL (C++11) |
非法参数 (宏常量) |
EIO (C++11) |
I/O 错误 (宏常量) |
EISCONN (C++11) |
接头已连接 (宏常量) |
EISDIR (C++11) |
是目录 (宏常量) |
ELOOP (C++11) |
符号链接级别过多 (宏常量) |
EMFILE (C++11) |
文件描述符值过大 (宏常量) |
EMLINK (C++11) |
链接过多 (宏常量) |
EMSGSIZE (C++11) |
消息过大 (宏常量) |
ENAMETOOLONG (C++11) |
文件名过长 (宏常量) |
ENETDOWN (C++11) |
网络不工作 (宏常量) |
ENETRESET (C++11) |
连接被网络打断 (宏常量) |
ENETUNREACH (C++11) |
网络不可抵达 (宏常量) |
ENFILE (C++11) |
系统中打开文件过多 (宏常量) |
ENOBUFS (C++11) |
无缓冲空间可用 (宏常量) |
ENODATA (C++11) |
流头已读取队列中无消息 (宏常量) |
ENODEV (C++11) |
无此设备 (宏常量) |
ENOENT (C++11) |
无此文件或目录 (宏常量) |
ENOEXEC (C++11) |
可执行文件格式错误 (宏常量) |
ENOLCK (C++11) |
无可用锁 (宏常量) |
ENOLINK (C++11) |
链接已切断 (宏常量) |
ENOMEM (C++11) |
空间不足 (宏常量) |
ENOMSG (C++11) |
无所需类型消息 (宏常量) |
ENOPROTOOPT (C++11) |
协议不可用 (宏常量) |
ENOSPC (C++11) |
设备无剩余空间 (宏常量) |
ENOSR (C++11) |
无流资源 (宏常量) |
ENOSTR (C++11) |
非流 (宏常量) |
ENOSYS (C++11) |
不支持的函数 (宏常量) |
ENOTCONN (C++11) |
未连接的接头 (宏常量) |
ENOTDIR (C++11) |
非目录 (宏常量) |
ENOTEMPTY (C++11) |
目录非空 (宏常量) |
ENOTRECOVERABLE (C++11) |
状态不可恢复 (宏常量) |
ENOTSOCK (C++11) |
非接头 (宏常量) |
ENOTSUP (C++11) |
不支持 (宏常量) |
ENOTTY (C++11) |
不适合的 I/O 控制操作 (宏常量) |
ENXIO (C++11) |
无此设备或地址 (宏常量) |
EOPNOTSUPP (C++11) |
接头上不支持的操作 (宏常量) |
EOVERFLOW (C++11) |
值过大而无法存入数据类型 (宏常量) |
EOWNERDEAD (C++11) |
先前拥有者已死 (宏常量) |
EPERM (C++11) |
操作不允许 (宏常量) |
EPIPE (C++11) |
管道损坏 (宏常量) |
EPROTO (C++11) |
协议错误 (宏常量) |
EPROTONOSUPPORT (C++11) |
不支持的协议 (宏常量) |
EPROTOTYPE (C++11) |
接头类型错误的协议 (宏常量) |
ERANGE |
结果过大 (宏常量) |
EROFS (C++11) |
只读文件系统 (宏常量) |
ESPIPE (C++11) |
非法寻位 (宏常量) |
ESRCH (C++11) |
无此进程 (宏常量) |
ETIME (C++11) |
流 ioctl() 超时 (宏常量) |
ETIMEDOUT (C++11) |
连接超时 (宏常量) |
ETXTBSY (C++11) |
文本文件忙 (宏常量) |
EWOULDBLOCK (C++11) |
操作会阻塞 (宏常量) |
EXDEV (C++11) |
跨设备链接 (宏常量) |
要求所有值均为唯一值,但 EOPNOTSUPP
与 ENOTSUP
的值可以相同,且 EAGAIN
与 EWOULDBLOCK
的值可以相同。
示例
运行此代码
#include <cerrno> #include <cstring> #include <iomanip> #include <iostream> #define SHOW(x) std::cout << std::setw(15) << #x << ": " << std::strerror(x) << '\n' int main() { std::cout << "Known error codes/messages:\n\n"; SHOW( E2BIG ); SHOW( EACCES ); SHOW( EADDRINUSE ); SHOW( EADDRNOTAVAIL ); SHOW( EAFNOSUPPORT ); SHOW( EAGAIN ); SHOW( EALREADY ); SHOW( EBADF ); SHOW( EBADMSG ); SHOW( EBUSY ); SHOW( ECANCELED ); SHOW( ECHILD ); SHOW( ECONNABORTED ); SHOW( ECONNREFUSED ); SHOW( ECONNRESET ); SHOW( EDEADLK ); SHOW( EDESTADDRREQ ); SHOW( EDOM ); SHOW( EEXIST ); SHOW( EFAULT ); SHOW( EFBIG ); SHOW( EHOSTUNREACH ); SHOW( EIDRM ); SHOW( EILSEQ ); SHOW( EINPROGRESS ); SHOW( EINTR ); SHOW( EINVAL ); SHOW( EIO ); SHOW( EISCONN ); SHOW( EISDIR ); SHOW( ELOOP ); SHOW( EMFILE ); SHOW( EMLINK ); SHOW( EMSGSIZE ); SHOW( ENAMETOOLONG ); SHOW( ENETDOWN ); SHOW( ENETRESET ); SHOW( ENETUNREACH ); SHOW( ENFILE ); SHOW( ENOBUFS ); SHOW( ENODATA ); SHOW( ENODEV ); SHOW( ENOENT ); SHOW( ENOEXEC ); SHOW( ENOLCK ); SHOW( ENOLINK ); SHOW( ENOMEM ); SHOW( ENOMSG ); SHOW( ENOPROTOOPT ); SHOW( ENOSPC ); SHOW( ENOSR ); SHOW( ENOSTR ); SHOW( ENOSYS ); SHOW( ENOTCONN ); SHOW( ENOTDIR ); SHOW( ENOTEMPTY ); SHOW( ENOTRECOVERABLE ); SHOW( ENOTSOCK ); SHOW( ENOTSUP ); SHOW( ENOTTY ); SHOW( ENXIO ); SHOW( EOPNOTSUPP ); SHOW( EOVERFLOW ); SHOW( EOWNERDEAD ); SHOW( EPERM ); SHOW( EPIPE ); SHOW( EPROTO ); SHOW( EPROTONOSUPPORT ); SHOW( EPROTOTYPE ); SHOW( ERANGE ); SHOW( EROFS ); SHOW( ESPIPE ); SHOW( ESRCH ); SHOW( ETIME ); SHOW( ETIMEDOUT ); SHOW( ETXTBSY ); SHOW( EWOULDBLOCK ); SHOW( EXDEV ); }
可能的输出:
Known error codes/messages: E2BIG: Argument list too long EACCES: Permission denied EADDRINUSE: Address already in use EADDRNOTAVAIL: Cannot assign requested address EAFNOSUPPORT: Address family not supported by protocol EAGAIN: Resource temporarily unavailable EALREADY: Operation already in progress EBADF: Bad file descriptor EBADMSG: Bad message EBUSY: Device or resource busy ECANCELED: Operation canceled ECHILD: No child processes ECONNABORTED: Software caused connection abort ECONNREFUSED: Connection refused ECONNRESET: Connection reset by peer EDEADLK: Resource deadlock avoided EDESTADDRREQ: Destination address required EDOM: Numerical argument out of domain EEXIST: File exists EFAULT: Bad address EFBIG: File too large EHOSTUNREACH: No route to host EIDRM: Identifier removed EILSEQ: Invalid or incomplete multibyte or wide character EINPROGRESS: Operation now in progress EINTR: Interrupted system call EINVAL: Invalid argument EIO: Input/output error EISCONN: Transport endpoint is already connected EISDIR: Is a directory ELOOP: Too many levels of symbolic links EMFILE: Too many open files EMLINK: Too many links EMSGSIZE: Message too long ENAMETOOLONG: File name too long ENETDOWN: Network is down ENETRESET: Network dropped connection on reset ENETUNREACH: Network is unreachable ENFILE: Too many open files in system ENOBUFS: No buffer space available ENODATA: No data available ENODEV: No such device ENOENT: No such file or directory ENOEXEC: Exec format error ENOLCK: No locks available ENOLINK: Link has been severed ENOMEM: Cannot allocate memory ENOMSG: No message of desired type ENOPROTOOPT: Protocol not available ENOSPC: No space left on device ENOSR: Out of streams resources ENOSTR: Device not a stream ENOSYS: Function not implemented ENOTCONN: Transport endpoint is not connected ENOTDIR: Not a directory ENOTEMPTY: Directory not empty ENOTRECOVERABLE: State not recoverable ENOTSOCK: Socket operation on non-socket ENOTSUP: Operation not supported ENOTTY: Inappropriate ioctl for device ENXIO: No such device or address EOPNOTSUPP: Operation not supported EOVERFLOW: Value too large for defined data type EOWNERDEAD: Owner died EPERM: Operation not permitted EPIPE: Broken pipe EPROTO: Protocol error EPROTONOSUPPORT: Protocol not supported EPROTOTYPE: Protocol wrong type for socket ERANGE: Numerical result out of range EROFS: Read-only file system ESPIPE: Illegal seek ESRCH: No such process ETIME: Timer expired ETIMEDOUT: Connection timed out ETXTBSY: Text file busy EWOULDBLOCK: Resource temporarily unavailable EXDEV: Invalid cross-device link
参阅
(C++11) |
列出所有标准 <cerrno> 宏常量的 std::error_condition 枚举 (类) |
展开成 POSIX 兼容的线程局域错误号变量的宏 (宏变量) | |
显示对应当前错误的字符串于 stderr (函数) | |
返回给定错误码的文本版本 (函数) |