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
source share