저는 C++ 11 표준을 연구 중입니다. 나는 error_code와 errno가 서로 관련이 있는지 알고 싶었다. 그렇다면 어떻게? 그러면 어떤 조건에서 errno가 설정되고 어떤 조건에서 error_code가 설정 될 것으로 예상해야합니까?error_code 대 errno
나는 이것을 이해하기 위해 작은 테스트 프로그램을 만들었지 만 여전히 혼란 스럽다. 도와주세요. 이러한 기능은 예외가 발생하지 C 라이브러리 또는 OS 함수이다 -
#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
제목에 'error_code'라는 제목이 있지만 코드에 언급되지 않았습니다. –
@Keith : e.code() 함수는 value 값을 가진 값을 읽는 error_code의 객체를 반환합니다. – tshah06