- system_error[meta header]
- std[meta namespace]
- class[meta id-type]
- cpp11[meta cpp]
namespace std {
class system_error : public runtime_error;
}
- runtime_error[link /reference/stdexcept.md]
system_error
クラスは、OSのエラーを表現するerror_code
クラスのオブジェクトを包含した例外クラスである。
名前 | 説明 | 対応バージョン |
---|---|---|
system_error( error_code ec, const string& what_arg); system_error( error_code ec, const char* what_arg); system_error( error_code ec); system_error(int ev, const error_category & cat, const string& what_arg); system_error(int ev, const error_category & cat, const char* what_arg); system_error(int ev, const error_category & cat); |
error_code オブジェクト or エラー値 + エラーカテゴリとエラー理由の文字列からsystem_error オブジェクトを生成する |
C++11 |
const error_code & code() const noexcept; |
包含しているerror_code オブジェクトへの参照を取得する |
C++11 |
virtual const char* what() const noexcept; |
メッセージを取得する メッセージ内容は実装依存だが、「what_arg + ": " + code().message() 」という形式になると予想できる。 |
C++11 |
#include <iostream>
#include <system_error>
#include <string>
int main()
{
try {
std::error_code ec(static_cast<int>(std::errc::invalid_argument),
std::generic_category());
throw std::system_error(ec, "system error!");
}
catch (std::system_error& e) {
const std::error_code& ec = e.code();
std::cout << ec.value() << std::endl;
std::cout << e.what() << std::endl;
}
}
- std::system_error[color ff0000]
- std::error_code[link error_code.md]
- std::errc::invalid_argument[link errc.md]
- std::generic_category()[link generic_category.md]
- ec.value()[link error_code/value.md]
22
system error!: Invalid argument
- C++11
- Clang: ??
- GCC:
- GCC, C++11 mode: 4.7.0
- ICC: ??
- Visual C++: 2010