std::error_condition
(C++17)<system_error>
std::error_condition
holds a platform-independent value identifying an error condition. Like std::error_code , it is uniquely identified by an integer value and a std::error_category , but unlike std::error_code , the value is not platform-dependent.
A typical implementation holds one integer data member (the value) and a pointer to an std::error_category .
[edit] Member functions
[edit] Non-member functions
error_condition
s and error_code
s (function) [edit]
[edit] Helper classes
[edit] Notes
The comparison between a std::error_code and a std::error_condition
is defined by their error categories. Notably, an error condition of std::generic_category may compare equal to an error code of a specific category (e.g. std::system_category ), if they represent the same kind of error.
A std::errc value can be compared to an error code via implicit conversion to std::error_condition
.
#include <cerrno> #include <iostream> #include <system_error> #include <Windows.h> int main() { std::error_code ec{ERROR_FILE_EXISTS, std::system_category ()}; std::error_condition econd{EEXIST, std::generic_category ()}; std::cout.setf(std::ios::boolalpha); std::cout << (ec == econd) << '\n'; // typically true std::cout << (ec == std::errc::file_exists ) << '\n'; // ditto std::cout << (ec == make_error_code(std::errc::file_exists )) << '\n'; // false: // different category }
Possible output:
true true false