Difference between revisions of "cpp/io/io errc/make error code"
From cppreference.com
(Expand example to show the main purpose of this method.) |
(Added LWG issue #2087 DR (part 2/3).) |
||
Line 1: | Line 1: | ||
{{cpp/title|make_error_code{{dsc small|(std::io_errc)}}}} | {{cpp/title|make_error_code{{dsc small|(std::io_errc)}}}} | ||
{{cpp/io/io_errc/navbar}} | {{cpp/io/io_errc/navbar}} | ||
− | {{ddcl | header=ios | since=c++11 | | + | {{ddcl|header=ios|since=c++11| |
std::error_code make_error_code( std::io_errc e ) noexcept; | std::error_code make_error_code( std::io_errc e ) noexcept; | ||
}} | }} | ||
− | Constructs an {{lc|std::error_code}} object from a value of type {{lc|std::io_errc}} as if by {{c|return std::error_code(static_cast<int>(e), std::iostream_category())}}. This function is called by the constructor of {{lc|std::error_code}} | + | Constructs an {{lc|std::error_code}} object from a value of type {{lc|std::io_errc}} as if by {{c|return std::error_code(static_cast<int>(e), std::iostream_category())}}. |
+ | |||
+ | This function is called by the constructor of {{lc|std::error_code}} with an {{lc|std::io_errc}} argument. | ||
===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_code}} that holds the error code number from {{ | + | A value of type {{lc|std::error_code}} 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() | ||
{ | { | ||
Line 32: | Line 34: | ||
<< ec.category().name() << '\n'; | << ec.category().name() << '\n'; | ||
} | } | ||
− | + | |output= | |
Error code from io_errc::stream has category iostream | Error code from io_errc::stream has category iostream | ||
}} | }} | ||
+ | |||
+ | ===Defect reports=== | ||
+ | {{dr list begin}} | ||
+ | {{dr list item|wg=lwg|dr=2087|std=C++11|before={{tt|make_error_code(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_code}} | + | {{dsc inc|cpp/error/dsc error_code}} |
− | {{dsc inc | cpp/io/dsc io_errc}} | + | {{dsc inc|cpp/io/dsc io_errc}} |
− | {{dsc inc | cpp/error/errc/dsc make_error_code}} | + | {{dsc inc|cpp/error/errc/dsc make_error_code}} |
− | {{dsc inc | cpp/thread/future_errc/dsc make_error_code}} | + | {{dsc inc|cpp/thread/future_errc/dsc make_error_code}} |
{{dsc end}} | {{dsc end}} | ||
− | + | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
Latest revision as of 00:57, 21 August 2023
Defined in header <ios>
|
||
std::error_code make_error_code( std::io_errc e ) noexcept; |
(since C++11) | |
Constructs an std::error_code object from a value of type std::io_errc as if by return std::error_code(static_cast<int>(e), std::iostream_category()).
This function is called by the constructor of std::error_code with an std::io_errc argument.
Contents |
[edit] Parameters
e | - | error code number |
[edit] Return value
A value of type std::error_code 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_code ec = std::make_error_code(std::io_errc::stream); // This works because of the overloaded method // and the is_error_code_enum specialization. ec = std::io_errc::stream; std::cout << "Error code from io_errc::stream has category " << ec.category().name() << '\n'; }
Output:
Error code from io_errc::stream has category iostream
[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_code(io_errc) was not declared noexcept
|
declared noexcept |
[edit] See also
(C++11) |
holds a platform-dependent error code (class) |
(C++11) |
the IO stream error codes (enum) |
(C++11) |
creates error code value for errc enum e (function) |
constructs a future error code (function) |