Namespaces
Variants
Views
Actions

std::future_error

From cppreference.com
< cpp‎ | thread
Revision as of 19:54, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <future>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td >
class future_error;
</td>

<td class="t-dcl-nopad"> </td> <td > (since C++11) </td> </tr> Template:ddcl list end

The class std::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 to std::system_error, this exception carries an error code compatible with std::error_code.

cpp/error/exceptioncpp/error/logic errorstd-future error-inheritance.svg
About this image

Inheritance diagram

Contents

Member functions

Template:cpp/thread/future error/dcl list constructorTemplate:cpp/thread/future error/dcl list codeTemplate:cpp/thread/future error/dcl list what

Inherited from std::logic_error

Inherited from std::exception

Member functions

[virtual]
destructs the exception object
(virtual public member function of std::exception) [edit]
[virtual]
returns an explanatory string
(virtual public member function of std::exception) [edit]

Example

#include <future>
#include <iostream>
 
int main()
{
    std::future<int> empty;
    try {
        int n = empty.get();
    } catch (const std::future_error& e) {
        std::cout << "Caught a future_error with code \"" << e.code()
                  << "\"\nMessage: \"" << e.what() << "\"\n";
    }
}

Output:

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

See also

Template:cpp/thread/dcl list future errc