gpt4 book ai didi

c++ - 错误代码与错误条件

转载 作者:IT老高 更新时间:2023-10-28 12:51:28 28 4
gpt4 key购买 nike

我不太明白为什么我们需要区分错误代码 (std::error_code) 和错误 condition(std::error_condition) ,他们不是一回事吗?错误条件与错误代码的优势是什么?

最佳答案

来自 http://en.cppreference.com/w/cpp/error/error_condition

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 时,您的错误代码并不特定于您正在处理的平台。

带有 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 将引用特定于您的平台、硬件等的内容。

同时使用两者可能是有利的。 error_condition 是“可移植的抽象”,因此将是提供给用户的通用错误消息,而 error_code 将是对特定调试有用的平台相关信息.

A typical implementation [of error_condition] holds one integer data member (the value) and a pointer to an std::error_category.

关于c++ - 错误代码与错误条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16687403/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com