Difference between revisions of "cpp/io/io errc/make error condition"
From cppreference.com
m (Update links.) |
(Added LWG issue #2087 DR (part 3/3).) |
||
(7 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
{{cpp/title|make_error_condition{{dsc small|(std::io_errc)}}}} | {{cpp/title|make_error_condition{{dsc small|(std::io_errc)}}}} | ||
{{cpp/io/io_errc/navbar}} | {{cpp/io/io_errc/navbar}} | ||
− | {{ddcl | header=ios | | + | {{ddcl|header=ios|since=c++11| |
− | std::error_condition make_error_condition( std::io_errc e ); | + | std::error_condition make_error_condition( std::io_errc e ) noexcept; |
}} | }} | ||
Line 9: | Line 9: | ||
===Parameters=== | ===Parameters=== | ||
{{par begin}} | {{par begin}} | ||
− | {{par | e | error code number}} | + | {{par|e|error code number}} |
{{par end}} | {{par end}} | ||
===Return value=== | ===Return value=== | ||
− | A value of type {{lc|std::error_condition}} that holds the error code number from {{ | + | A value of type {{lc|std::error_condition}} that holds the error code number from {{c|e}} associated with the error category {{c|"iostream"}}. |
===Example=== | ===Example=== | ||
{{example | {{example | ||
− | + | |code= | |
− | + | ||
#include <iostream> | #include <iostream> | ||
#include <system_error> | #include <system_error> | ||
+ | |||
int main() | int main() | ||
{ | { | ||
− | std::error_condition ec | + | std::error_condition ec = std::make_error_condition(std::io_errc::stream); |
std::cout << "error condition for io_errc::stream has value " << ec.value() | std::cout << "error condition for io_errc::stream has value " << ec.value() | ||
<< "\nand message \"" << ec.message() << "\"\n"; | << "\nand message \"" << ec.message() << "\"\n"; | ||
} | } | ||
− | + | |output= | |
error condition for io_errc::stream has value 1 | error condition for io_errc::stream has value 1 | ||
and message "unspecified iostream_category error" | and message "unspecified iostream_category error" | ||
}} | }} | ||
+ | |||
+ | ===Defect reports=== | ||
+ | {{dr list begin}} | ||
+ | {{dr list item|wg=lwg|dr=2087|std=C++11|before={{tt|make_error_condition(io_errc)}} was not declared {{c/core|noexcept}}|after=declared {{c/core|noexcept}}}} | ||
+ | {{dr list end}} | ||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | + | {{dsc inc|cpp/error/dsc error_condition}} | |
− | {{dsc inc | cpp/error/dsc error_condition}} | + | {{dsc inc|cpp/io/dsc io_errc}} |
− | {{dsc inc | cpp/io/dsc io_errc}} | + | |
{{dsc end}} | {{dsc end}} | ||
− | + | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
Latest revision as of 01:04, 21 August 2023
Defined in header <ios>
|
||
std::error_condition make_error_condition( std::io_errc e ) noexcept; |
(since C++11) | |
Constructs an std::error_condition object from a value of type std::io_errc as if by return std::error_condition(static_cast<int>(e), std::iostream_category()).
Contents |
[edit] Parameters
e | - | error code number |
[edit] Return value
A value of type std::error_condition that holds the error code number from e associated with the error category "iostream".
[edit] Example
Run this code
#include <iostream> #include <system_error> int main() { std::error_condition ec = std::make_error_condition(std::io_errc::stream); std::cout << "error condition for io_errc::stream has value " << ec.value() << "\nand message \"" << ec.message() << "\"\n"; }
Output:
error condition for io_errc::stream has value 1 and message "unspecified iostream_category error"
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 2087 | C++11 | make_error_condition(io_errc) was not declared noexcept
|
declared noexcept |
[edit] See also
(C++11) |
holds a portable error code (class) |
(C++11) |
the IO stream error codes (enum) |