io_errc

enum class
<ios> <iostream>

std::io_errc

enum class io_errc;
Input/output error conditions
This enum class type defines the error conditions of the iostream category.

The enum includes at least the following label:
io_errc labelvaluedescription
stream1Error in stream

All library implementations define at least this value (stream, with a value of 1), but may provide additional values, especially if they require to produce additional error codes for the iostream category.

Values of the enum type io_errc may be used to create error_condition objects to be compared against the value returned by the code member of ios_base::failure.

Although notice that exceptions of type ios_base::failure may also carry error codes from other categories (such as from the system_category).

Non-member function overloads


Non-member class specializations


Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// io_errc example
#include <iostream>     // std::cin, std::cerr, std::ios,
                        // std::make_error_condition, std::ios_errc
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() == std::make_error_condition(std::io_errc::stream) )
      std::cerr << "stream error condition\n"; 
    else
      std::cerr << "some other error condition\n";
  }

  return 0;
}

Possible output:

failure caught: stream error condition


See also