My question: What is the correct way to construct std::error_code
instances from errno
values on POSIX and GetLastError()
on Windows so th
This is an old question, but I haven't really found a good answer on SO. The accepted answer confuses me a little as it seems to give an error_condition
rather than an error_code
. I have settled on the following for myself on POSIX:
std::error_code error_code_from_errno(int errno_code) {
return std::make_error_code(static_cast(errno_code));
}
This always gives me the correct category (generic or system). I've had problems in the past where error codes with the same errno code compared as not equal because one had generic_category
and the other had system_category
.