error_code 类

表示特定于实现的低级别系统错误。

语法

class error_code;

备注

error_code 类类型的对象存储错误代码值和指向对象的指针,该对象表示描述所报告的低级别系统错误的错误代码类别

成员

构造函数

名称 描述
error_code 构造 error_code 类型的对象。

Typedef

名称 描述
value_type 表示存储的错误代码值的类型。

函数

名称 描述
assign 向错误代码分配错误代码值和类别。
category 返回错误类别。
clear 清除错误代码值和类别。
default_error_condition 返回默认的错误条件。
message 返回错误代码的名称。

运算符

名称 描述
operator== 测试各 error_code 对象是否相等。
operator!= 测试各 error_code 对象是否不相等。
operator< 测试 error_code 对象是否小于要比较的传入对象 error_code
operator= error_code 对象分配新的枚举值。
operator bool 转换 error_code 类型的变量。

assign

向错误代码分配错误代码值和类别。

void assign(value_type val, const error_category& _Cat);

参数

val
要存储在 error_code 中的错误代码值。

_Cat
要存储在 error_code 中的错误类别。

备注

此成员函数存储 val 作为错误代码值和指向 _Cat 的指针

category

返回错误类别。

const error_category& category() const;

备注

clear

清除错误代码值和类别。

clear();

注解

此成员函数存储零错误代码值和指向 generic_category 对象的指针。

default_error_condition

返回默认的错误条件。

error_condition default_error_condition() const;

返回值

default_error_condition 指定的 error_condition

备注

此成员函数返回 category().default_error_condition(value())

error_code

构造 error_code 类型的对象。

error_code();

error_code(value_type val, const error_category& _Cat);

template <class _Enum>
error_code(_Enum _Errcode,
    typename enable_if<is_error_code_enum<_Enum>::value,
    error_code>::type* = 0);

参数

val
要存储在 error_code 中的错误代码值。

_Cat
要存储在 error_code 中的错误类别。

_Errcode
要存储在 error_code 中的枚举值。

备注

第一个构造函数存储零错误代码值和指向 generic_category 的指针。

第二个构造函数存储 val 作为错误代码值和指向 error_category 的指针

第三个构造函数存储 (value_type)_Errcode 作为错误代码值和指向 generic_category 的指针。

message

返回错误代码的名称。

string message() const;

返回值

表示错误代码名称的 string

备注

此成员函数返回 category().message(value())

operator==

测试各 error_code 对象是否相等。

bool operator==(const error_code& right) const;

参数

right
要测试是否相等的对象。

返回值

如果对象相等,则为 true;如果对象不相等,则为 false

备注

该成员运算符将返回 category() == right.category() && value == right.value()

operator!=

测试各 error_code 对象是否不相等。

bool operator!=(const error_code& right) const;

参数

right
要测试是否不相等的对象。

返回值

如果 error_code 对象不等于 right 中的传入对象 error_code,则为 true;否则为 false

注解

该成员运算符将返回 !(*this == right)

operator<

测试 error_code 对象是否小于要比较的传入对象 error_code

bool operator<(const error_code& right) const;

参数

right
要比较的 error_code 对象。

返回值

如果 error_code 对象小于要比较的传入对象 error_code,则为 true;否则为 false

备注

该成员运算符将返回 category() < right.category() || category() == right.category() && value < right.value()

operator=

error_code 对象分配新的枚举值。

template <class _Enum>
typename enable_if<is_error_code_enum<_Enum>::value, error_code>::type&
    operator=(_Enum _Errcode);

参数

_Errcode
要向 error_code 对象分配的枚举值。

返回值

对正在通过成员函数向其分配新枚举值的 error_code 对象的引用。

注解

成员运算符存储 (value_type)_Errcode 作为错误代码值和指向 generic_category 的指针。 它将返回 *this

operator bool

转换 error_code 类型的变量。

explicit operator bool() const;

返回值

error_code 对象的布尔值。

备注

仅在不等于零时,此运算符才返回可转换为 true 的值。 返回类型只能转换为 bool,而不能转换为 void * 或其他已知的标量类型。

value

返回存储的错误代码值。

value_type value() const;

返回值

value_type 类型的已存储错误代码值。

value_type

表示存储的错误代码值的类型。

typedef int value_type;

注解

此类型定义是 int 的同义词。