Namespaces
Variants

std:: underflow_error

From cppreference.net
헤더 파일에 정의됨 <stdexcept>
class underflow_error ;

예외로 던져질 객체의 유형을 정의합니다. 산술 언더플로우 오류(즉, 계산 결과가 비정규 부동 소수점 값인 상황)를 보고하는 데 사용될 수 있습니다.

표준 라이브러리 구성 요소는 이 예외를 던지지 않습니다 (수학 함수는 math_errhandling 에 지정된 대로 언더플로우 오류를 보고합니다). 그러나 타사 라이브러리는 이를 사용합니다. 예를 들어, boost.math std::underflow_error 를 던집니다. 만약 boost::math::policies::throw_on_error 가 활성화된 경우 (기본 설정).

std::underflow_error 의 모든 멤버 함수는 constexpr 입니다: 상수 표현식 평가에서 std::underflow_error 객체를 생성하고 사용하는 것이 가능합니다.

그러나, std::underflow_error 객체는 일반적으로 constexpr 일 수 없습니다. 동적으로 할당된 저장 공간은 동일한 상수 표현식 평가에서 해제되어야 하기 때문입니다.

(C++26부터)
cpp/error/exception cpp/error/runtime error std-underflow error-inheritance.svg

상속 다이어그램

목차

멤버 함수

(생성자)
주어진 메시지로 새로운 underflow_error 객체를 생성합니다
(public member function)
operator=
underflow_error 객체를 대체합니다
(public member function)

std::underflow_error:: underflow_error

underflow_error ( const std:: string & what_arg ) ;
(1) (constexpr since C++26)
underflow_error ( const char * what_arg ) ;
(2) (constexpr since C++26)
underflow_error ( const underflow_error & other ) ;
(3) (noexcept since C++11)
(constexpr since C++26)
1) 예외 객체를 what_arg 를 설명 문자열로 사용하여 생성합니다. 생성 후 std:: strcmp ( what ( ) , what_arg. c_str ( ) ) == 0 입니다.
2) 예외 객체를 what_arg 를 설명 문자열로 사용하여 생성합니다. 생성 후 std:: strcmp ( what ( ) , what_arg ) == 0 입니다.
3) 복사 생성자입니다. * this other 모두 동적 타입 std::underflow_error 를 가지면 std:: strcmp ( what ( ) , other. what ( ) ) == 0 입니다. 복사 생성자에서는 예외가 발생할 수 없습니다.

매개변수

what_arg - 설명 문자열
other - 복사할 다른 예외 객체

예외

1,2) std::bad_alloc 을 발생시킬 수 있습니다.

참고

std::underflow_error 의 복사는 예외를 발생시키는 것이 허용되지 않기 때문에, 이 메시지는 일반적으로 별도로 할당된 참조 카운트 문자열로 내부에 저장됩니다. 이것이 std::string&& 를 취하는 생성자가 없는 이유이기도 합니다: 어차피 내용을 복사해야 하기 때문입니다.

LWG 이슈 254 의 해결 이전에는, 비복사 생성자는 std::string 만 받아들일 수 있었습니다. 이는 std::string 객체를 생성하기 위해 동적 할당을 필수적으로 만들었습니다.

LWG 이슈 471 의 해결 이후, 파생된 표준 예외 클래스는 공개적으로 접근 가능한 복사 생성자를 가져야 합니다. 원본 객체와 복사된 객체에 대해 what() 으로 얻은 설명 문자열이 동일한 한 암시적으로 정의될 수 있습니다.

std::underflow_error:: operator=

underflow_error & operator = ( const underflow_error & other ) ;
(C++11부터 noexcept)
(C++26부터 constexpr)

내용을 other 의 내용으로 할당합니다. * this other 모두 동적 타입이 std::underflow_error 인 경우, 할당 후 std:: strcmp ( what ( ) , other. what ( ) ) == 0 이 됩니다. 복사 할당 연산자에서는 예외가 발생하지 않습니다.

매개변수

other - 할당할 다른 예외 객체

반환값

* this

참고

LWG 이슈 471 의 해결 이후, 파생된 표준 예외 클래스는 공개적으로 접근 가능한 복사 할당 연산자를 가져야 합니다. 원본 객체와 복사된 객체에 대해 what() 으로 얻은 설명 문자열이 동일한 한 암시적으로 정의될 수 있습니다.

std:: runtime_error 에서 상속됨


std:: exception 로부터 상속됨

멤버 함수

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

참고 사항

기능 테스트 매크로 표준 기능
__cpp_lib_constexpr_exceptions 202502L (C++26) constexpr 예외 타입

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 254 C++98 const char * 를 받는 생성자가 누락됨 추가됨
LWG 471 C++98 std::underflow_error 의 설명 문자열
복사본이 구현에 따라 정의됨
원본 std::underflow_error 객체와
동일함