错误代码与错误条件

编程入门 行业动态 更新时间:2024-10-10 13:14:21
本文介绍了错误代码与错误条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I don't quite get why do we need to make a distinction between error code (std::error_code) and an error condition(std::error_condition), aren't they the same thing? What are the advantages of an error condition vs error code?

推荐答案

从 en.cppreference/w/cpp/error/error_condition

std :: error_condition是一个与平台无关的错误代码。像 std :: error_code一样,它由整数值和 std :: error_category唯一标识,但与std :: error_code不同,该值不是平台相关的。 p>

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 。

So, the advantage is your error code isn't specific to the platform you're working on when using std::error:condition.

使用 std :: error_code

每个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 将引用特定于您的平台,一个硬件等

So, the error_code will reference something specific to your platform, a piece of hardware etc etc.

使用两者可能是有利的。 error_condition 是可移植抽象,因此将是给用户的通用错误消息, error_code

It may be advantageous to use both. The error_condition is the "portable abstraction" so would be the generic error message to give to the user and the error_code would be the platform dependent information that would be useful for specific debug.

典型的[error_condition]实现保存一个整数数据成员)和a指向std :: error_category的指针。

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

更多推荐

错误代码与错误条件

本文发布于:2023-11-28 03:48:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640836.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误代码   错误   条件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!