std::errc(3)
π NAME π
okay bestie, welcome to the std::errc(3) page. The NAME is literally std::errc β that's the main character, no cap. π
πΈ Synopsis πΈ
Defined in header <system_error>:
enum class errc; (since C++11)
The scoped enumeration std::errc defines the values of portable error conditions that correspond to the POSIX error codes. It's giving "glow-up for errno," fr fr. β¨
π Member constants π
Each constant pairs a cute C++ name with its equivalent POSIX error code β here's the whole roster, zero skips:
address_family_not_supportedβEAFNOSUPPORTaddress_in_useβEADDRINUSEaddress_not_availableβEADDRNOTAVAILalready_connectedβEISCONNargument_list_too_longβE2BIGargument_out_of_domainβEDOMbad_addressβEFAULTbad_file_descriptorβEBADFbad_messageβEBADMSGbroken_pipeβEPIPEconnection_abortedβECONNABORTEDconnection_already_in_progressβEALREADYconnection_refusedβECONNREFUSEDconnection_resetβECONNRESETcross_device_linkβEXDEVdestination_address_requiredβEDESTADDRREQdevice_or_resource_busyβEBUSYdirectory_not_emptyβENOTEMPTYexecutable_format_errorβENOEXECfile_existsβEEXISTfile_too_largeβEFBIGfilename_too_longβENAMETOOLONGfunction_not_supportedβENOSYShost_unreachableβEHOSTUNREACHidentifier_removedβEIDRMillegal_byte_sequenceβEILSEQinappropriate_io_control_operationβENOTTYinterruptedβEINTRinvalid_argumentβEINVALinvalid_seekβESPIPEio_errorβEIOis_a_directoryβEISDIRmessage_sizeβEMSGSIZEnetwork_downβENETDOWNnetwork_resetβENETRESETnetwork_unreachableβENETUNREACHno_buffer_spaceβENOBUFSno_child_processβECHILDno_linkβENOLINKno_lock_availableβENOLCKno_message_available(deprecated) βENODATAno_messageβENOMSGno_protocol_optionβENOPROTOOPTno_space_on_deviceβENOSPCno_stream_resources(deprecated) βENOSRno_such_device_or_addressβENXIOno_such_deviceβENODEVno_such_file_or_directoryβENOENTno_such_processβESRCHnot_a_directoryβENOTDIRnot_a_socketβENOTSOCKnot_a_stream(deprecated) βENOSTRnot_connectedβENOTCONNnot_enough_memoryβENOMEMnot_supportedβENOTSUPoperation_canceledβECANCELEDoperation_in_progressβEINPROGRESSoperation_not_permittedβEPERMoperation_not_supportedβEOPNOTSUPPoperation_would_blockβEWOULDBLOCKowner_deadβEOWNERDEADpermission_deniedβEACCESprotocol_errorβEPROTOprotocol_not_supportedβEPROTONOSUPPORTread_only_file_systemβEROFSresource_deadlock_would_occurβEDEADLKresource_unavailable_try_againβEAGAINresult_out_of_rangeβERANGEstate_not_recoverableβENOTRECOVERABLEstream_timeout(deprecated) βETIMEtext_file_busyβETXTBSYtimed_outβETIMEDOUTtoo_many_files_open_in_systemβENFILEtoo_many_files_openβEMFILEtoo_many_linksβEMLINKtoo_many_symbolic_link_levelsβELOOPvalue_too_largeβEOVERFLOWwrong_protocol_typeβEPROTOTYPE
β¨ Non-member functions β¨
make_error_code(std::errc)β creates error code value forerrcenume(C++11) (function)make_error_condition(std::errc)β creates an error condition for anerrcvaluee(C++11) (function)
π¦ Helper classes π¦
is_error_condition_enum<std::errc>β extends the type traitstd::is_error_condition_enumto identifyerrcvalues as error conditions (C++11) (function template)
π₯ Example π₯
// Run this code
#include <filesystem>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <system_error>
#include <thread>
void print_error(const std::string& details, std::error_code
error_code)
{
std::string value_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";
}
void print_errno(const std::string& details, int errno_value = errno)
{
print_error(details, std::make_error_code(std::errc(errno_value)));
}
int main()
{
std::cout << "Detaching a not-a-thread...\n";
try
{
std::thread().detach();
}
catch (const std::system_error& e)
{
print_error("Error detaching empty thread", e.code());
}
std::cout << "Opening nonexistent file...\n";
std::ifstream nofile{"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::ifstream dir_stream{"dir"};
[[maybe_unused]] char c = 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::fstream write_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
LWG 3869β applied toC++11.- Behavior as published: the member constants
no_message_available,no_stream_resources,not_a_streamandstream_timeoutreferred to the obsolete POSIX STREAMS API [1]. - Correct behavior: deprecated them.
- Behavior as published: the member constants
- β Although the corresponding POSIX error numbers
ENODATA,ENOSR,ENOSTRandETIMEwere 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 π«Ά
error_codeβ holds a platform-dependent error code (C++11) (class)error_conditionβ holds a portable error code (C++11) (class)
okay that's the whole page, bestie! source/version: http://cppreference.com β date: 2024.06.10 πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms