function
<ios> <iostream>

std::iostream_category

const error_category& iostream_category();
Return iostream category
Returns a reference to the static object of the error_category type that has the following characteristics:

error_condition objects describing errors that correspond to the enum type io_errc are associated to this category. What constitutes one of these correspondences depends on the operating system and the particular library implementation.

Parameters

none

Return value

A reference to the iostream error_category object.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// io_errc example
// iostream_category example
#include <iostream>     // std::cin, std::cerr, std::ios,
                        // std::iostream_category
int main () {
  std::cin.exceptions (std::ios::failbit|std::ios::badbit);
  try {
    std::cin.rdbuf(nullptr);    // throws
  } catch (std::ios::failure& e) {
    std::cerr << "failure caught: ";
    if ( e.code().category() == std::iostream_category() )
      std::cerr << "error code of the iostream category\n"; 
    else
      std::cerr << "error code of some other category\n";
  }
  return 0;
}


Possible output:

failure caught: error code of the iostream category

Exception safety

No-throw guarantee: this function never throws exceptions.

See also