std:: system_category
|
定义于头文件
<system_error>
|
||
|
const
std::
error_category
&
system_category
(
)
noexcept
;
|
(C++11 起) | |
获取操作系统报告错误对应的静态错误类别对象引用。该对象需要重写虚函数 std::error_category::name() 以返回指向字符串 "system" 的指针。同时需要重写虚函数 std::error_category::default_error_condition() ,将符合 POSIX errno 值的错误代码映射到 std::generic_category 。
目录 |
参数
(无)
返回值
对具有未指定运行时类型的静态对象的引用,该对象派生自 std::error_category 。
注释
在 Windows 系统上,
system_category()
通常会将某些
Windows 错误代码
映射为 POSIX 错误代码。在 POSIX 系统上,
system_category()
除了名称不同外,往往等价于
std::generic_category()
。
示例
#include <iomanip> #include <iostream> #include <string> #include <system_error> int main() { for (int const code : {EDOM, 10001}) { const std::error_condition econd = std::system_category().default_error_condition(code); std::cout << "Category: " << econd.category().name() << '\n' << "Value: " << econd.value() << '\n' << "Message: " << econd.message() << "\n\n"; } }
可能的输出:
Category: generic Value: 33 Message: Numerical argument out of domain Category: system Value: 10001 Message: Unknown error 10001
参见
|
(C++11)
|
标识通用错误类别
(函数) |
|
(C++11)
|
枚举所有标准
<cerrno>
宏常数的
std::error_condition
枚举
(类) |