【发布时间】:2013-04-05 05:57:08
【问题描述】:
我正在研究 C++11 标准。我想了解 error_code 和 errno 是否相互关联?如果是,那怎么办? 如果不是,那么我应该在哪些条件下设置 errno 以及在哪些条件下设置 error_code?p>
我做了一个小测试程序来理解这一点,但仍然有点困惑。请帮忙。
#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() 函数返回我正在使用值函数读取其值的 error_code 对象。
标签: c++ c++11 error-handling errno