参考:http://blog.think-async.com/2010/04/system-error-support-in-c0x-part-3.html
参考:http://zh.highscore.de/cpp/boost/errorhandling.html
1. std::error_code
value(): 当前平台的错误代码
category();
2. std::error_condition
value(): 与平台无关的错误代码,无视当前操作系统
category();
3. std::error_category
name():
message():
4. std::errc
作为std::error_condition常量的占位符。
可以通过std::errc的占位符来创建std::error_code或std::error_condition
5. std::error_code与std::errc可以直接进行“==”的比较
详情参考: http://blog.think-async.com/2010/04/system-error-support-in-c0x-part-3.html
#include <iostream>
#include <system_error>
#include <thread>
int main()
{
try {
std::thread().detach(); // detaching a not-a-thread
} catch (const std::system_error& e) {
std::cout << "Caught a system_error\n";
if(e.code() == std::errc::invalid_argument)
std::cout << "The error condition is std::errc::invalid_argument\n";
std::cout << "the error description is " << e.what() << '\n';
}
}
将std::errc转化成error_condition还是error_code由注册决定
当std::errc注册为error_condition时:
template <> struct is_error_condition_enum<errc> : true_type {};
采用:bool operator==(const error_code& a,const error_condition& b);
当std::errc注册为error_code时:
template <> struct is_error_code_enum<errc> : true_type {};
采用:
bool operator==(const error_code& a,const error_code& b);
5. make_error_code: 根据std::errc的值构建std::error_code
6. make_error_condition: 根据std::errc的值构建std::error_condition