Namespaces
Variants

std:: future_error

From 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 로부터 상속됨

멤버 함수

[virtual]
예외 객체를 파괴함
( std::exception 의 virtual public member function)
[virtual]
설명 문자열을 반환함
( std::exception 의 virtual public member function)

예제

#include <future>
#include <iostream>
int main()
{
    std::future<int> empty;
    try
    {
        int n = empty.get(); // 동작은 정의되지 않았으나
                             // 일부 구현에서는 std::future_error를 throw함
    }
    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"

참고 항목

future 오류 코드를 식별합니다
(enum)