thread_future_error

thread_future_error (미래 오류 예외)

이 페이지는 C++11에서 도입된 std::future_error 예외 클래스에 대해 설명해요. 이 예외는 비동기 실행과 공유 상태를 다루는 스레드 라이브러리 함수들(std::future, std::promise 등)이 실패할 때 던져져요. std::system_error와 비슷하게, 이 예외는 std::error_code와 호환되는 오류 코드를 담고 있어요.

출처: cppreference

본문

정의

<future> 헤더에 정의되어 있어요.

정의
class future_error; (C++11부터)

설명

std::future_error 클래스는 비동기 실행과 공유 상태를 다루는 스레드 라이브러리 함수들이 실패할 때 던져지는 예외 객체를 정의해요. std::system_error와 유사하게, 이 예외는 std::error_code와 호환되는 오류 코드를 담고 있어요.

상속 구조

std::future_errorstd::logic_error를 상속하고, std::logic_error는 다시 std::exception을 상속해요.

멤버 함수

멤버 함수 설명
(생성자) std::future_error 객체를 생성해요.
operator= std::future_error 객체를 치환해요.
code 오류 코드를 반환해요.
what 오류 코드에 해당하는 설명 문자열을 반환해요.

std::logic_error에서 상속

std::exception에서 상속

멤버 함수

멤버 함수 설명
(소멸자) [virtual] 예외 객체를 소멸시켜요. (std::exception의 가상 public 멤버 함수)
what [virtual] 설명 문자열을 반환해요. (std::exception의 가상 public 멤버 함수)

예제

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

같이 보기

| future_errc (C++11) | 미래 오류 코드를 식별해요. (enum) |

더 알아보기 (Learn more)

cppreference