Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::future_error

      From cppreference.com
      <cpp‎ |thread
       
       
      Concurrency support library
      Threads
      (C++11)
      (C++20)
      this_thread namespace
      (C++11)
      (C++11)
      (C++11)
      Cooperative cancellation
      Mutual exclusion
      Generic lock management
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      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
       
       
      Defined in header<future>
      class future_error;
      (since C++11)

      The classstd::future_error defines an exception object that is thrown on failure by the functions in the thread library that deal with asynchronous execution and shared states (std::future,std::promise, etc). Similar tostd::system_error, this exception carries an error code compatible withstd::error_code.

      std-future error-inheritance.svg

      Contents

      [edit]Member functions

      creates astd::future_error object
      (public member function)[edit]
      replaces thestd::future_error object
      (public member function)[edit]
      returns the error code
      (public member function)[edit]
      returns the explanatory string specific to the error code
      (public member function)[edit]

      Inherited fromstd::logic_error

      Inherited fromstd::exception

      Member functions

      [virtual]
      destroys the exception object
      (virtual public member function ofstd::exception)[edit]
      [virtual]
      returns an explanatory string
      (virtual public member function ofstd::exception)[edit]

      [edit]Example

      Run this code
      #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";}}

      Possible output:

      Caught a future_error with code "future:3"Message: "No associated state"

      [edit]See also

      identifies the future error codes
      (enum)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/thread/future_error&oldid=167572"

      [8]ページ先頭

      ©2009-2025 Movatter.jp