Namespaces
Variants
Views
Actions

std::ios_base::failure

From cppreference.com
< cpp‎ | io‎ | ios base
Revision as of 16:57, 2 November 2012 by P12bot (Talk | contribs)

Defined in header <ios>
class failure;

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

cpp/error/exceptionstd-ios base-failure-2003-inheritance.svg
About this image

Inheritance diagram (until C++11)

cpp/error/exceptioncpp/error/runtime errorcpp/error/system errorstd-ios base-failure-inheritance.svg
About this image

Inheritance diagram (since C++11)

Contents

Member functions

Template:cpp/io/ios base/failure/dcl list constructor

Inherited from std::system_error

Member functions

returns error code
(public member function of std::system_error) [edit]
[virtual]
returns explanatory string
(virtual public member function of std::system_error) [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

See also

Template:cpp/io/dcl list io errc