错误代码与错误条件
我不太明白为什么我们需要区分错误代码(std :: error_code)
和错误条件std :: error_condition)
,他们不是一回事吗?错误条件与错误代码的优点是什么?
I don't quite get why do we need to make a distinction between error code (std::error_code)
and an error condition(std::error_condition)
, aren't they the same thing? What are the advantages of an error condition vs error code?
从 http://en.cppreference.com/w/cpp/error/error_condition
std :: error_condition是一个与平台无关的错误代码。像
std :: error_code一样,它由整数值和
std :: error_category唯一标识,但与std :: error_code不同,该值不是
平台相关的。 p>
std::error_condition is a platform-independent error code. Like std::error_code, it is uniquely identified by an integer value and a std::error_category, but unlike std::error_code, the value is not platform-dependent.
所以,优点是你的错误代码不是特定于你使用 std :: error:condition
。
So, the advantage is your error code isn't specific to the platform you're working on when using std::error:condition
.
使用 std :: error_code
每个std :: error_code对象保存一对来自操作系统的
错误代码,或一些低级接口
Each std::error_code object holds a pair of error code originating from the operating system, or some low-level interface
因此, error_code
将引用特定于您的平台,一个硬件等
So, the error_code
will reference something specific to your platform, a piece of hardware etc etc.
使用两者可能是有利的。 error_condition
是可移植抽象,因此将是给用户的通用错误消息, error_code
It may be advantageous to use both. The error_condition
is the "portable abstraction" so would be the generic error message to give to the user and the error_code
would be the platform dependent information that would be useful for specific debug.
典型的[error_condition]实现保存一个整数数据成员)和
a指向std :: error_category的指针。
A typical implementation [of error_condition] holds one integer data member (the value) and a pointer to an std::error_category.