Do we really need std :: error_category and std :: error_condition?

So, in my journey, to understand how it works std::error_code, I begin to wonder if we really need std::error_conditionand std::error_category. I'm trying to implement something in this and this lesson and the amount of work is nontrivial, and it's pretty fragile (I'm currently stuck trying to figure out why this code causes errors to be associated with duplicate characters.

Is it easier to subclass to std::error_codeadd a property message, and then let it std::error_codebe comparable to the enumeration where error codes are defined? I'm trying to understand why I std::error_categoryand std::error_conditionall.

+4
source share
1 answer

The main advantage is that it error_codeis a type for copying that can be transferred from library to library without the need for dynamic allocation of memory or templates, which makes it very light and easy to use.

If you are writing a fully autonomous project, then yes, error codes and categories seem too complicated when you can just have your own type.

, , (, ASIO, think-async.com). error_code, - , , .

, , .

: , , . , , , , .

+5

Source: https://habr.com/ru/post/1684406/


All Articles