Namespaces
Variants

std:: future_error

From ja.cppreference.net
Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
Generic lock management
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
(C++11)
future_error
(C++11)
Safe reclamation
Hazard pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11) (deprecated in C++20)
(C++11) (deprecated in C++20)
Memory ordering
(C++11) (deprecated in C++26)
Free functions for atomic operations
Free functions for atomic flags
定義済みヘッダー <future>
class future_error ;
(C++11以降)

クラス std::future_error は、非同期実行と共有状態を扱うスレッドライブラリの関数( std::future 、 std::promise など)が失敗した際にスローされる例外オブジェクトを定義します。 std::system_error と同様に、この例外は std::error_code と互換性のあるエラーコードを保持します。

cpp/error/exception cpp/error/logic error std-future error-inheritance.svg

継承図

目次

メンバー関数

std::future_errorオブジェクトを生成する
(public member function)
std::future_errorオブジェクトを置き換える
(public member function)
エラーコードを返す
(public member function)
エラーコード固有の説明文字列を返す
(public member function)

std:: logic_error から継承

std::exception から継承

メンバ関数

例外オブジェクトを破棄する
(std::exception の仮想公開メンバ関数)
[仮想]
説明文字列を返す
(std::exception の仮想公開メンバ関数)

例

#include <future>
#include <iostream>
int main()
{
    std::future<int> empty;
    try
    {
        int n = empty.get(); // 動作は未定義だが、
                             // 一部の実装では 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"

関連項目

フューチャーエラーコードを識別する
(列挙型)