虽然我正在使用C++ 11,但这个问题与提升相关,因为我正在处理错误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
}
Run Code Online (Sandbox Code Playgroud)
如果我在抛出所需的异常(no_such_file_or_directory)时打印错误值:
// ...
} catch (filesystem_error& e) {
cout << "Value: " << e.code().value() << endl;
}
Run Code Online (Sandbox Code Playgroud)
我得到了价值2.它的价值是相同的e.code().default_error_condition().value().
我的问题是:不同错误类别的不同错误条件是否具有相同的值?我的意思是,我是否需要同时检查错误类别和错误值,以确保我收到特定错误?在这种情况下,最干净的方法是什么?