I/O manipulators | ||||
Print functions(C++23) | ||||
C-style I/O | ||||
Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
Streams | ||||
Abstractions | ||||
File I/O | ||||
String I/O | ||||
Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
Synchronized Output | ||||
(C++20) | ||||
Types | ||||
Error category interface | ||||
(C++11) | ||||
(C++11) |
Member functions | ||||
State functions | ||||
Formatting | ||||
Miscellaneous | ||||
basic_ios::exceptions | ||||
Protected member functions | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) |
std::ios_base::iostate exceptions()const; | (1) | |
void exceptions(std::ios_base::iostate except); | (2) | |
Gets and sets the exception mask of the stream. The exception mask determines which error states trigger exceptions of typefailure.
Contents |
except | - | exception mask |
This section is incomplete Reason: discussLWG2349 and link from ios_base::clear, and from (un)formatted(i/o)utputfunction requirement pages (or perhaps the behavior should be fully elaborated on the requirement pages and linked from here). See alsostackoverflow.com/a/35089910 |
#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(conststd::ios_base::failure& fail){// handle exception herestd::cout<< fail.what()<<'\n';}}
Possible output:
basic_ios::clear: iostream error