命名空间
变体
操作

错误号

来自 cppreference.com
< cpp‎ | error

<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)
STREAM 头读取队列中没有可用消息
(宏常量)
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)
没有 STREAM 资源
(宏常量)
ENOSTR
(C++11)
不是 STREAM
(宏常量)
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)
无效的 seek
(宏常量)
ESRCH
(C++11)
没有这样的进程
(宏常量)
ETIME
(C++11)
STREAM ioctl() 超时
(宏常量)
ETIMEDOUT
(C++11)
连接超时
(宏常量)
ETXTBSY
(C++11)
文本文件忙
(宏常量)
EWOULDBLOCK
(C++11)
操作将被阻塞
(宏常量)
EXDEV
(C++11)
跨设备链接
(宏常量)

所有值都必须唯一,但 EOPNOTSUPPENOTSUP 的值可能相同,EAGAINEWOULDBLOCK 的值也可能相同。

[编辑] 示例

#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)
the std::error_condition 列出所有标准 <cerrno> 宏常量的枚举
(类) [编辑]
扩展为与 POSIX 兼容的线程本地错误号变量的宏
(宏变量)[编辑]
将与当前错误对应的字符字符串显示到 stderr
(函数) [编辑]
返回给定错误码的文本版本
(函数) [编辑]
C 文档 for 错误号