Namespaces
Variants

std::system_error::system_error

cppreference.net에서
 
 
유틸리티 라이브러리
일반 유틸리티
관계 연산자 (C++20에서 폐지됨)
정수 비교 함수
(C++20)(C++20)(C++20)    
(C++20)
스왑 및 형식 연산
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
공통 어휘 형식
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
 
 
system_error( std::error_code ec );
(1) (C++11부터)
system_error( std::error_code ec, const std::string& what_arg );
(2) (C++11부터)
system_error( std::error_code ec, const char* what_arg );
(2) (C++11부터)
system_error( int ev, const std::error_category& ecat );
(3) (C++11부터)
system_error( int ev, const std::error_category& ecat,
              const std::string& what_arg );
(4) (C++11부터)
system_error( int ev, const std::error_category& ecat,
              const char* what_arg );
(4) (C++11부터)
system_error( const system_error& other ) noexcept;
(5) (C++11부터)

새로운 시스템 오류 객체를 생성합니다.

1) 오류 코드 ec로 생성합니다.
2) 오류 코드 ec와 설명 문자열 what_arg로 생성합니다. what()이 반환하는 문자열은 반드시 what_arg을(를) 부분 문자열로 포함합니다.
3) 기본 오류 코드 ev와 연결된 오류 범주 ecat로 생성합니다.
4) 기본 오류 코드 ev, 연결된 오류 범주 ecat 및 설명 문자열 what_arg로 생성합니다. what()이 반환하는 문자열은 반드시 what_arg을(를) 부분 문자열로 포함합니다(문자열에 null 문자가 포함되지 않는다고 가정).
5) 복사 생성자. 내용을 other의 내용으로 초기화합니다. *this과 other의 동적 형식이 모두 std::system_error이면 std::strcmp(what(), other.what()) == 0입니다.

매개변수

ec - 오류 코드
ev - ecat 와 연관된 열거형의 기본 오류 코드
ecat - 오류 카테고리
what_arg - 설명 문자열
other - 복사할 다른 system_error

예제

system_error 예외를 errno 값으로부터 생성하는 방법을 보여줍니다.

#include <iostream>
#include <system_error>
int main()
{
    try
    {
        throw std::system_error(EDOM, std::generic_category(), "FIX ME");
    }
    catch (const std::system_error& ex)
    {
        std::cout << "code:    [" << ex.code() << "]\n"
                     "message: [" << ex.code().message() << "]\n"
                     "what:    [" << ex.what() << "]\n";
    }
}

가능한 출력:

code:    [generic:33]
message: [Numerical argument out of domain]
what:    [FIX ME: Numerical argument out of domain]