Defined in header <ios> | ||||
---|---|---|---|---|
| (since C++11) |
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
.
Parameters
(none).
Return value
A reference to the static object of unspecified runtime type, derived from std::error_category
.
Exceptions
noexcept
specification: noexcept
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #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" << "Error code: " << e.code().value() << " (" << e.code().message() << ")\n" << "Error category: " << e.code().category().name() << '\n' ; } } |
Possible output:
1 2 3 | Caught an ios_base::failure. Error code: 1 (unspecified iostream_category error) Error category: iostream |
See also
stream exception (public member class of std::ios_base ) | |
(C++11) | the IO stream error codes (enum) |
Please login to continue.