From cppreference.com
The scoped enumeration std::errc defines the values of portable error conditions that correspond to the POSIX error codes.
Member constants
Name Equivalent POSIX Error address_family_not_supportedEAFNOSUPPORTaddress_in_useEADDRINUSEaddress_not_availableEADDRNOTAVAILalready_connectedEISCONNargument_list_too_longE2BIGargument_out_of_domainEDOMbad_addressEFAULTbad_file_descriptorEBADFbad_messageEBADMSGbroken_pipeEPIPEconnection_abortedECONNABORTEDconnection_already_in_progressEALREADYconnection_refusedECONNREFUSEDconnection_resetECONNRESETcross_device_linkEXDEVdestination_address_requiredEDESTADDRREQdevice_or_resource_busyEBUSYdirectory_not_emptyENOTEMPTYexecutable_format_errorENOEXECfile_existsEEXISTfile_too_largeEFBIGfilename_too_longENAMETOOLONGfunction_not_supportedENOSYShost_unreachableEHOSTUNREACHidentifier_removedEIDRMillegal_byte_sequenceEILSEQinappropriate_io_control_operationENOTTYinterruptedEINTRinvalid_argumentEINVALinvalid_seekESPIPEio_errorEIOis_a_directoryEISDIRmessage_sizeEMSGSIZEnetwork_downENETDOWNnetwork_resetENETRESETnetwork_unreachableENETUNREACHno_buffer_spaceENOBUFSno_child_processECHILDno_linkENOLINKno_lock_availableENOLCKno_message_available(deprecated)ENODATAno_messageENOMSGno_protocol_optionENOPROTOOPTno_space_on_deviceENOSPCno_stream_resources(deprecated)ENOSRno_such_device_or_addressENXIOno_such_deviceENODEVno_such_file_or_directoryENOENTno_such_processESRCHnot_a_directoryENOTDIRnot_a_socketENOTSOCKnot_a_stream(deprecated)ENOSTRnot_connectedENOTCONNnot_enough_memoryENOMEMnot_supportedENOTSUPoperation_canceledECANCELEDoperation_in_progressEINPROGRESSoperation_not_permittedEPERMoperation_not_supportedEOPNOTSUPPoperation_would_blockEWOULDBLOCKowner_deadEOWNERDEADpermission_deniedEACCESprotocol_errorEPROTOprotocol_not_supportedEPROTONOSUPPORTread_only_file_systemEROFSresource_deadlock_would_occurEDEADLKresource_unavailable_try_againEAGAINresult_out_of_rangeERANGEstate_not_recoverableENOTRECOVERABLEstream_timeout(deprecated)ETIMEtext_file_busyETXTBSYtimed_outETIMEDOUTtoo_many_files_open_in_systemENFILEtoo_many_files_openEMFILEtoo_many_linksEMLINKtoo_many_symbolic_link_levelsELOOPvalue_too_largeEOVERFLOWwrong_protocol_typeEPROTOTYPENon-member functions
Helper classes
Example
Run this code
#include<filesystem>#include<fstream>#include<iomanip>#include<iostream>#include<string>#include<system_error>#include<thread>voidprint_error(conststd::string&details,std::error_codeerror_code){std::stringvalue_name;if(error_code==std::errc::invalid_argument)value_name="std::errc::invalid_argument";if(error_code==std::errc::no_such_file_or_directory)value_name="std::errc::no_such_file_or_directory";if(error_code==std::errc::is_a_directory)value_name="std::errc::is_a_directory";if(error_code==std::errc::permission_denied)value_name="std::errc::permission_denied";std::cout<<details<<":\n "<<std::quoted(error_code.message())<<" ("<<value_name<<")\n\n";}voidprint_errno(conststd::string&details,interrno_value=errno){print_error(details,std::make_error_code(std::errc(errno_value)));}intmain(){std::cout<<"Detaching a not-a-thread...\n";try{std::thread().detach();}catch(conststd::system_error&e){print_error("Error detaching empty thread",e.code());}std::cout<<"Opening nonexistent file...\n";std::ifstreamnofile{"nonexistent-file"};if(!nofile.is_open())print_errno("Error opening nonexistent file for reading");std::cout<<"Reading from directory as a file...\n";std::filesystem::create_directory("dir");std::ifstreamdir_stream{"dir"};[[maybe_unused]]charc=dir_stream.get();if(!dir_stream.good())print_errno("Error reading data from directory");std::cout<<"Open read-only file for writing...\n";std::fstream{"readonly-file",std::ios::out};std::filesystem::permissions("readonly-file",std::filesystem::perms::owner_read);std::fstreamwrite_readonly("readonly-file",std::ios::out);if(!write_readonly.is_open())print_errno("Error opening read-only file for writing");}Possible output:
Detaching a not-a-thread... Error detaching empty thread: "Invalid argument" (std::errc::invalid_argument) Opening nonexistent file... Error opening nonexistent file for reading: "No such file or directory" (std::errc::no_such_file_or_directory) Reading from directory as a file... Error reading data from directory: "Is a directory" (std::errc::is_a_directory) Open read-only file for writing... Error opening read-only file for writing: "Permission denied" (std::errc::permission_denied) Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
C++11 the member constants no_message_available,
no_stream_resources, not_a_stream and stream_timeout
referred to the obsolete POSIX STREAMS API
deprecated them
Although the corresponding POSIX error numbers ENODATA, ENOSR, ENOSTR and ETIME were marked "obsolescent" in POSIX 2017, the STREAMS API was optional and not required for conformance to the previous POSIX standard (because popular unix-like systems refused to implement it).
See also