Namespaces
Variants

std::basic_ios<CharT,Traits>:: exceptions

From cppreference.net
std:: ios_base :: iostate exceptions ( ) const ;
(1)
void exceptions ( std:: ios_base :: iostate except ) ;
(2)

스트림의 예외 마스크를 가져오고 설정합니다. 예외 마스크는 어떤 오류 상태가 failure 타입의 예외를 발생시키는지 결정합니다.

1) 예외 마스크를 반환합니다.
2) 예외 마스크를 except 로 설정합니다. 호출 시 스트림이 예외 마스크로 커버되는 오류 상태를 가지고 있으면, 예외가 즉시 트리거됩니다.

목차

매개변수

except - exception mask

반환값

1) 현재 예외 마스크.
2) (없음)

참고 사항

예제

#include <fstream>
#include <iostream>
int main() 
{
    int ivalue;
    try
    {
        std::ifstream in("in.txt");
        in.exceptions(std::ifstream::failbit); // may throw
        in >> ivalue; // may throw
    }
    catch (const std::ios_base::failure& fail)
    {
        // handle exception here
        std::cout << fail.what() << '\n';
    }
}

가능한 출력:

basic_ios::clear: iostream error