错误代码与错误条件 [英] error code vs error condition

查看:129
本文介绍了错误代码与错误条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太明白为什么我们需要区分错误代码(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?

推荐答案

http://en.cppreference.com/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.

这篇关于错误代码与错误条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆