std::future_error
來自 cppreference.com
在標頭檔案 <future> 中定義 |
||
class future_error; |
(C++11 起) | |
類 std::future_error 定義了一個異常物件,當執行緒庫中處理非同步執行和共享狀態(std::future, std::promise 等)的函式失敗時丟擲。與 std::system_error 類似,此異常攜帶一個與 std::error_code 相容的錯誤碼。
繼承圖
目錄 |
[編輯] 成員函式
建立 std::future_error 物件(公有成員函式) | |
替換 std::future_error 物件(公有成員函式) | |
返回錯誤碼 (公有成員函式) | |
返回特定於錯誤碼的解釋性字串 (公有成員函式) |
繼承自 std::logic_error
繼承自 std::exception
成員函式
[虛擬函式] |
銷燬異常物件 ( std::exception 的虛公有成員函式) |
[虛擬函式] |
返回解釋字串 ( std::exception 的虛公有成員函式) |
[編輯] 示例
執行此程式碼
#include <future> #include <iostream> int main() { std::future<int> empty; try { int n = empty.get(); // The behavior is undefined, but // some implementations throw std::future_error } catch (const std::future_error& e) { std::cout << "Caught a future_error with code \"" << e.code() << "\"\nMessage: \"" << e.what() << "\"\n"; } }
可能的輸出
Caught a future_error with code "future:3" Message: "No associated state"
[編輯] 參閱
(C++11) |
標識 future 錯誤程式碼 (列舉) |