Error_code vs errno

I am studying C ++ 11 standards. I wanted to understand if error_code and errno are related to each other? If so, how? If not, under what conditions should I expect errno to be installed and in what conditions will the error_code parameter be set?

I did a little test program to figure this out, but still a little confused. Please, help.

#include <iostream> #include <system_error> #include <thread> #include <cstring> #include <cerrno> #include <cstdio> using namespace std; int main() { try { thread().detach(); } catch (const system_error & e) { cout<<"Error code value - "<<e.code().value()<<" ; Meaning - "<<e.what()<<endl; cout<<"Error no. - "<<errno<<" ; Meaning - "<<strerror(errno)<<endl; } } Output - Error code value - 22 ; Meaning - Invalid argument Error no. - 0 ; Meaning - Success 
+4
source share
1 answer

errno used by those functions that document this as a side effect of their error encountering - these functions are the C library or OS functions that never throw an exception. system_error used by the C ++ standard library for cases where you use the library features documented to throw this exception. Completely separate. Ultimately, read your documents!

+6
source

All Articles