命名空间
变体
操作

std::system_category

来自 cppreference.cn
< cpp‎ | 错误
定义于头文件 <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)
std::error_condition 枚举,列出所有标准 <cerrno> 宏常量
(类) [编辑]