- system_error[meta header]
- std[meta namespace]
- class[meta id-type]
- cpp11[meta cpp]
namespace std {
class error_category;
}
error_category
クラスは、エラー情報を分類するための基底クラスである。
エラーコードから対応するエラーメッセージを取得する処理が異なる場合などで、error_category
クラスを派生して環境固有のエラー情報を取得するためのクラスを定義できる。
名前 |
説明 |
対応バージョン |
equivalent |
エラーコードとエラー状態の等値比較 |
C++11 |
operator== |
等値比較 |
C++11 |
operator!= |
非等値比較 (C++20からoperator== により使用可能) |
C++11 |
operator<=> |
三方比較 |
C++20 |
operator< |
左辺が右辺より小さいか比較 (C++20からoperator<=> により使用可能) |
C++11 |
bool operator<=(const error_category&) const noexcept; |
左辺が右辺以下か比較 (operator<=> により使用可能) |
C++20 |
bool operator>(const error_category&) const noexcept; |
左辺が右辺より大きいか比較 (operator<=> により使用可能) |
C++20 |
bool operator>=(const error_category&) const noexcept; |
左辺が右辺以上か比較 (operator<=> により使用可能) |
C++20 |
名前 |
説明 |
対応バージョン |
name |
カテゴリ名を取得 |
C++11 |
message |
エラーコードに対応するメッセージを取得 |
C++11 |
#include <iostream>
#include <system_error>
#include <string>
class user_defined_error_category : public std::error_category {
public:
const char* name() const noexcept override
{
return "user defined error";
}
std::string message(int ev) const override
{
return "error message";
}
};
const std::error_category& user_defined_category()
{
static user_defined_error_category cat;
return cat;
}
int main()
{
const std::error_category& cat = user_defined_category();
std::cout << cat.name() << std::endl;
}
- std::error_category[color ff0000]