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 值的 error_code 到 std::generic_category

目录

参数

(无)

返回值

到导出自 std::error_category 的未指定运行时类型的静态对象的引用。

示例

#include <iostream>
#include <system_error>
#include <iomanip>
#include <string>
 
int main()
{
    std::error_condition econd = std::system_category().default_error_condition(EDOM);
    std::cout << "Category: " << econd.category().name() << '\n'
              << "Value: " << econd.value() << '\n'
              << "Message: " << econd.message() << '\n';
 
    econd = std::system_category().default_error_condition(10001);
    std::cout << "Category: " << econd.category().name() << '\n'
              << "Value: " << econd.value() << '\n'
              << "Message: " << econd.message() << '\n';
}

输出:

Category: generic
Value: 33
Message: Numerical argument out of domain
Category: system
Value: 10001
Message: Unknown error 10001

参阅

鉴别通用错误类别
(函数)
(C++11)
列出所有标准 <cerrno> 宏常量的 std::error_condition 枚举
(类)

版本历史

  • (当前 | 先前 2017年6月6日 (二) 09:26Fruderica讨论 | 贡献. . (1,592字节) (-799). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 17:45P12bot讨论 | 贡献 . . (2,391字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 09:05P12bot讨论 | 贡献 . . (2,391字节) (-34). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 15:07P12bot讨论 | 贡献 . . (2,425字节) (+265). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 11:37P12讨论 | 贡献 . . (2,160字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 07:00TranslationBot讨论 | 贡献. . (2,160字节) (-44). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 14:25P12讨论 | 贡献 . . (2,204字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 13:00TranslationBot讨论 | 贡献. . (2,204字节) (+2,204). . (Translated from the English version using Google Translate)