ios_base::failure

The class failure defines the base class for the types of all objects thrown as exceptions, by functions in the iostreams library, to report errors detected during stream buffer operations.

namespace std {
    class failure : public system_error {
    public:
        explicit failure(
            const string& _Message, 
            const error_code& _Code = io_errc::stream
        );
        explicit failure(
            const char* _Str, 
            const error_code& _Code = io_errc::stream
        );
};

Remarks

The value returned by what() is a copy of _Message, possibly augmented with a test based on _Code. If _Code is not specified, the default value is make_error_code(io_errc::stream).

Example

// ios_base_failure.cpp
// compile with: /EHsc
#include <iostream>
#include <fstream>

int main ( ) 
{
   using namespace std;
   fstream file;
   file.exceptions(ios::failbit);
   try 
   {
      file.open( "rm.txt", ios_base::in );
      // Opens nonexistent file for reading
   }
   catch( ios_base::failure f ) 
   {
      cout << "Caught an exception: " << f.what() << endl;
   }
}
Caught an exception: ios_base::failbit set

Requirements

Header: <ios>

Namespace: std

See Also

Reference

ios_base Class

system_error Class

iostream Programming

iostreams Conventions

Other Resources

ios_base Members