【发布时间】:2014-07-13 23:26:52
【问题描述】:
虽然我使用的是 C++11,但这个问题与 boost 相关,因为我正在处理来自 boost::file_system 的错误。
以下情况:
try {
// If p2 doesn't exists, canonical throws an exception
// of No_such_file_or_directory
path p = canonical(p2);
// Other code
} catch (filesystem_error& e) {
if (e is the no_such_file_or_directory exception)
custom_message(e);
} // other catchs
}
如果我在抛出所需的异常(no_such_file_or_directory)时打印错误值:
// ...
} catch (filesystem_error& e) {
cout << "Value: " << e.code().value() << endl;
}
我得到了2 的值。与e.code().default_error_condition().value()的值相同。
我的问题是:来自不同错误类别的不同错误条件是否具有相同的值?我的意思是,我是否需要同时检查错误类别和错误值,以确保我收到特定错误?在这种情况下,最干净的方法是什么?
【问题讨论】:
标签: c++ boost boost-filesystem system-error