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
|
Dieser Abschnitt ist unvollständig
Grund: Diskussion von LWG2349 und Verlinkung von ios_base::clear, sowie von (un)formatted(i/o)utputfunction-Anforderungsseiten (oder möglicherweise sollte das Verhalten vollständig auf den Anforderungsseiten ausgearbeitet und von hier verlinkt werden). Siehe auch stackoverflow.com/a/35089910 |
Beispiel
Diesen Code ausführen
#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