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)

Ruft die Ausnahmemaske des Streams ab und legt sie fest. Die Ausnahmemaske bestimmt, welche Fehlerzustände Ausnahmen vom Typ failure auslösen.

1) Gibt die Exception-Maske zurück.
2) Setzt die Exception-Maske auf except . Wenn der Stream beim Aufruf einen Fehlerzustand hat, der durch die Exception-Maske abgedeckt wird, wird sofort eine Exception ausgelöst.

Inhaltsverzeichnis

Parameter

except - Exception-Maske

Rückgabewert

1) Die aktuelle Ausnahmemaske.
2) (keine)

Hinweise

Beispiel

#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';
    }
}

Mögliche Ausgabe:

basic_ios::clear: iostream error