From cppreference.com
std::ios_base::iostateexceptions()const; (1) voidexceptions(std::ios_base::iostateexcept); (2) Gets and sets the exception mask of the stream. The exception mask determines which error states trigger exceptions of type
.
1) Returns the exception mask.
2) Sets the exception mask to except. If the stream has an error state covered by the exception mask when called, an exception is immediately triggered.
Parameters
except - exception mask Return value
1) The current exception mask.
2) (none)
Notes
Example
Run this code
#include<fstream>#include<iostream>intmain(){intivalue;try{std::ifstreamin("in.txt");in.exceptions(std::ifstream::failbit);// may throwin>>ivalue;// may throw}catch(conststd::ios_base::failure&fail){// handle exception herestd::cout<<fail.what()<<'\n';}}Possible output:
basic_ios::clear: iostream error