◐ Shell
clean mode source ↗

std::future_error - cppreference.com

提供: cppreference.com

<tbody> </tbody>

class future_error;

(C++11以上)

クラス std::future_error は非同期実行および共有状態 (std::future, std::promise など) を扱うスレッドライブラリの関数によって失敗時に投げられる例外オブジェクトを定義します。 std::system_error と同様に、この例外は std::error_code と互換性のあるエラーコードを持ち運びます。

cpp/error/exceptioncpp/error/logic error

継承図

メンバ関数

std::logic_error から継承

#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"

関連項目