std::error_condition
來自 cppreference.com
定義於標頭檔案 <system_error> |
||
class error_condition; |
(C++11 起) | |
std::error_condition
包含一個識別錯誤條件的平臺獨立值。與 std::error_code 類似,它透過一個整數值和 std::error_category 唯一標識,但與 std::error_code 不同,該值不依賴於平臺。
典型的實現包含一個整數資料成員(值)和一個指向 std::error_category 的指標。
目錄 |
[編輯] 成員函式
構造一個 error_condition (public member function) | |
替換內容 (public member function) | |
替換內容 (public member function) | |
將 error_condition 設定為 generic_category 中的值 0(public member function) | |
獲取 error_condition 的值(public member function) | |
獲取此 error_condition 的 error_category (public member function) | |
獲取解釋性字串 (public member function) | |
檢查值是否非零 (public member function) |
[編輯] 非成員函式
(在 C++20 中移除)(在 C++20 中移除)(C++20) |
比較 error_condition 和 error_code (function) |
[編輯] 輔助類
(C++11) |
將列舉標識為 std::error_condition (class template) |
對 std::error_condition 的雜湊支援 (class template specialization) |
[編輯] 注意
std::error_code 和 std::error_condition
之間的比較由它們的錯誤類別定義。值得注意的是,如果它們代表相同型別的錯誤,std::generic_category 的錯誤條件可能與特定類別(例如 std::system_category)的錯誤程式碼比較相等。
一個 std::errc 值可以透過隱式轉換為 std::error_condition
來與錯誤程式碼進行比較。
執行此程式碼
#include <cerrno> #include <iostream> #include <system_error> #include <Windows.h> int main() { std::error_code ec{ERROR_FILE_EXISTS, std::system_category()}; std::error_condition econd{EEXIST, std::generic_category()}; std::cout.setf(std::ios::boolalpha); std::cout << (ec == econd) << '\n'; // typically true std::cout << (ec == std::errc::file_exists) << '\n'; // ditto std::cout << (ec == make_error_code(std::errc::file_exists)) << '\n'; // false: // different category }
可能的輸出
true true false
[編輯] 參閱
(C++11) |
儲存平臺相關錯誤碼 (類) |
(C++11) |
錯誤類別的基類 (類) |
為 errc 值 e 建立錯誤條件(函式) |