GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::future_error - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. future
  3. future_error

最終更新日時: 2026年10月03日 22時31分04秒 (JST)
Akira Takahashi が更新

履歴 編集

class
<future>

std::future_error(C++11)

namespace std {
  class future_error : public logic_error;
}

概要

future_errorは、future/promise操作でのエラーを扱うための例外クラスである。

メンバ関数

名前 説明 対応バージョン
future_error(error_code ec); error_codeオブジェクトからfuture_errorオブジェクトを生成する。
注:このクラスは標準ライブラリの内部で送出される例外クラスで、ユーザーが使用するものではないため、コンストラクタは説明のためにのみ記載されている。
C++11
C++14まで
future_error(future_errc e); future_errcオブジェクトからfuture_errorオブジェクトを生成する。
包含しているerror_codeオブジェクトをmake_error_code(e)から初期化する。
C++17
const error_code& code() const noexcept; 包含しているerror_codeオブジェクトへの参照を取得する C++11
virtual const char* what() const noexcept; エラー理由となる実装依存文字列(code.message())を返す C++11

例

#include <iostream>
#include <future>
#include <thread>
#include <utility>

void foo(std::promise<int> p)
{
  p.set_value(3);

  try {
    p.set_value(1); // promiseに2回以上書き込むとエラー
  }
  catch (std::future_error& e) {
    std::cout << "value:" << e.code().value() << std::endl;
    std::cout << "what:" << e.what() << std::endl;
  }
}

int main()
{
  std::promise<int> p;
  std::future<int> f = p.get_future();

  std::thread t(foo, std::move(p));

  std::cout << f.get() << std::endl;

  t.join();
}

出力例

3
value:3
what:Promise already satisfied

バージョン

言語

  • C++11

処理系

  • Clang: 9.0.1 ✅
  • GCC: 4.7.0 ✅
  • Visual C++: 2012 ✅

参照

  • P0517r0 Make future_error Constructible
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.