Namespaces
Variants

std:: system_error

From cppreference.net
Utilities library
헤더에 정의됨 <system_error>
class system_error ;
(C++11부터)

std::system_error 는 다양한 라이브러리 함수들(일반적으로 OS 기능과 인터페이스하는 함수들, 예를 들어 std::thread 의 생성자)에 의해 예외가 연관된 std::error_code 를 가질 때 발생하는 예외의 유형입니다. 이는 보고될 수 있습니다.

cpp/error/exception cpp/error/runtime error std-system error-inheritance.svg

상속 다이어그램

목차

멤버 함수

system_error 객체를 생성합니다
(public member function)
system_error 객체를 대체합니다
(public member function)
에러 코드를 반환합니다
(public member function)
[virtual]
설명 문자열을 반환합니다
(virtual public member function)

std:: exception 로부터 상속됨

멤버 함수

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

예제

#include <iostream>
#include <system_error>
#include <thread>
int main()
{
    try
    {
        std::thread().detach(); // attempt to detach a non-thread
    }
    catch(const std::system_error& e)
    {
        std::cout << "Caught system_error with code "
                     "[" << e.code() << "] meaning "
                     "[" << e.what() << "]\n";
    }
}

가능한 출력:

Caught system_error with code [generic:22] meaning [Invalid argument]