std::ios_base::failure
Min standard notice:
Header: <ios>
The class std::ios_base::failure defines an exception object that is thrown on failure by the functions in the Input/Output library.
# Declarations
class failure;
# Parameters
message: explanatory stringec: error code to identify the specific reason for the failureother: another failure to copy
# Return value
*this
# Notes
Because copying std::ios_base::failure is not permitted to throw exceptions, this message is typically stored internally as a separately-allocated reference-counted string. This is also why there is no constructor taking std::string&&: it would have to copy the content anyway.
# Example
#include <fstream>
#include <iostream>
int main()
{
std::ifstream f("doesn't exist");
try
{
f.exceptions(f.failbit);
}
catch (const std::ios_base::failure& e)
{
std::cout << "Caught an ios_base::failure.\n"
<< "Explanatory string: " << e.what() << '\n'
<< "Error code: " << e.code() << '\n';
}
}
# Defect reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 48 | C++98 | the constructor overload (1) initialized the base class std::exceptionwith msg, but the base class does not have a matching constructor | correspondingdescription removed |
| LWG 331 | C++98 | std::ios_base::failure declared a destructor without throw() | removed the destructor declaration |