std::iostream_category

Header: <ios>

Obtains a reference to the static error category object for iostream errors. The object is required to override the virtual function error_category::name() to return a pointer to the string “iostream”. It is used to identify error codes provided in the exceptions of type std::ios_base::failure.

# Declarations

const std::error_category& iostream_category() noexcept;

(since C++11)

# Return value

A reference to the static object of unspecified runtime type, derived from std::error_category.

# 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"
                  << "Error code: " << e.code().value() 
                  << " (" << e.code().message() << ")\n"
                  << "Error category: " << e.code().category().name() << '\n';
 
    }
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 2087C++11iostream_category was not declared noexceptdeclared noexcept

# See also