enum class
<system_error>

std::errc

enum class errc;
通用错误条件
enum class类型定义了错误条件通用类别

每个标签的值与等效的errno值定义的相同。

errc 标签errno 等效*
address_family_not_supportedEAFNOSUPPORT
address_in_useEADDRINUSE
address_not_availableEADDRNOTAVAIL
already_connectedEISCONN
argument_list_too_longE2BIG
argument_out_of_domainEDOM
bad_addressEFAULT
bad_file_descriptorEBADF
bad_messageEBADMSG
broken_pipeEPIPE
connection_abortedECONNABORTED
connection_already_in_progressEALREADY
connection_refusedECONNREFUSED
connection_resetECONNRESET
cross_device_linkEXDEV
destination_address_requiredEDESTADDRREQ
device_or_resource_busyEBUSY
directory_not_emptyENOTEMPTY
executable_format_errorENOEXEC
file_existsEEXIST
file_too_largeEFBIG
filename_too_longENAMETOOLONG
function_not_supportedENOSYS
host_unreachableEHOSTUNREACH
identifier_removedEIDRM
illegal_byte_sequenceEILSEQ
inappropriate_io_control_operationENOTTY
interruptedEINTR
invalid_argumentEINVAL
invalid_seekESPIPE
io_errorEIO
is_a_directoryEISDIR
message_sizeEMSGSIZE
network_downENETDOWN
network_resetENETRESET
network_unreachableENETUNREACH
no_buffer_spaceENOBUFS
no_child_processECHILD
no_linkENOLINK
no_lock_availableENOLOCK
no_messageENOMSG
no_message_availableENODATA
no_protocol_optionENOPROTOOPT
no_space_on_deviceENOSPC
no_stream_resourcesENOSR
no_such_deviceENODEV
no_such_device_or_addressENXIO
no_such_file_or_directoryENOENT
no_such_processESRCH
not_a_directoryENOTDIR
not_a_socketENOTSOCK
not_a_streamENOSTR
not_connectedENOTCONN
not_enough_memoryENOMEM
not_supportedENOTSUP
operation_canceledECANCELED
operation_in_progressEINPROGRESS
operation_not_permittedEPERM
operation_not_supportedEOPNOTSUPP
operation_would_blockEWOULDBLOCK
owner_deadEOWNERDEAD
permission_deniedEACCES
protocol_errorEPROTO
protocol_not_supportedEPROTONOSUPPORT
read_only_file_systemEROFS
resource_deadlock_would_occurEDEADLK
resource_unavailable_try_againEAGAIN
result_out_of_rangeERANGE
state_not_recoverableENOTRECOVERABLE
stream_timeoutETIME
text_file_busyETXTBSY
timed_outETIMEDOUT
too_many_files_openEMFILE
too_many_files_open_in_systemENFILE
too_many_linksEMLINK
too_many_symbolic_link_levelsELOOP
value_too_largeEOVERFLOW
wrong_protocol_typeEPROTOTYPE
* 这些是头文件<cerrno>中定义的宏常量。

请注意,errc 定义为enum class,而errno 的可能值是宏定义。

is_error_condition_enum 已针对此类型进行了特化,因此其valuetrue

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// errc example
#include <iostream>       // std::cout
#include <system_error>   // std::error_condition, std::errc, std::generic_category
#include <cerrno>         // EEXIST

int main()
{
  // two ways of creating the same error_condition:
  std::error_condition foo (std::errc::file_exists);
  std::error_condition bar (EEXIST, std::generic_category() );

  if (foo == bar) std::cout << foo.message();

  return 0;
}

可能的输出
File exists


另见