Namespaces
Variants
Views
Actions

std::ios_base::failure

From cppreference.com
Defined in header <ios>
class failure : public std::exception;
(until C++11)
class failure : public std::system_error;
(since C++11)

The class std::ios_base::failure defines an exception object that is thrown on failure by the functions in the Input/Output library.

Contents

[edit] Member functions

constructs the exception object
(public member function) [edit]

Inherited from std::system_error

Member functions

[virtual]
returns error code
(virtual public member function of std::system_error) [edit]
[virtual]
returns explanatory string
(virtual public member function of std::system_error) [edit]

Inherited from std::runtime_error


Inherited from std::exception

Member functions

[virtual]
destructs the exception object
(virtual public member function of std::exception) [edit]
[virtual]
returns explanatory string
(virtual public member function of std::exception) [edit]

[edit] Example

#include <iostream>
#include <fstream>
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';
    }
}

Output:

Caught an ios_base::failure.
Explanatory string: ios_base::clear: unspecified iostream_category error
Error code: iostream:1

[edit] See also

(C++11)
the IO stream error codes
(enum) [edit]