名稱空間
變體
操作

std::future_error

來自 cppreference.com
< cpp‎ | thread
 
 
併發支援庫
執行緒
(C++11)
(C++20)
this_thread 名稱空間
(C++11)
(C++11)
(C++11)
協同取消
互斥
(C++11)
通用鎖管理
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
條件變數
(C++11)
訊號量
門閂和屏障
(C++20)
(C++20)
期值
(C++11)
(C++11)
(C++11)
(C++11)
future_error
(C++11)
安全回收
(C++26)
危險指標
原子型別
(C++11)
(C++20)
原子型別的初始化
(C++11)(C++20 中已棄用)
(C++11)(C++20 中已棄用)
記憶體排序
(C++11)(C++26 中已棄用)
原子操作的自由函式
原子標誌的自由函式
 
 
在標頭檔案 <future> 中定義
class future_error;
(C++11 起)

std::future_error 定義了一個異常物件,當執行緒庫中處理非同步執行和共享狀態(std::future, std::promise 等)的函式失敗時丟擲。與 std::system_error 類似,此異常攜帶一個與 std::error_code 相容的錯誤碼。

cpp/error/exceptioncpp/error/logic errorstd-future error-inheritance.svg

繼承圖

目錄

[編輯] 成員函式

建立 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"

[編輯] 參閱

標識 future 錯誤程式碼
(列舉) [編輯]