Difference between revisions of "cpp/error/generic category"
From cppreference.com
m (merge noexcept) |
Andreas Krug (Talk | contribs) m (fmt, headers sorted, langlinks) |
||
Line 1: | Line 1: | ||
{{cpp/title|generic_category}} | {{cpp/title|generic_category}} | ||
{{cpp/error/navbar}} | {{cpp/error/navbar}} | ||
− | {{ddcl | header=system_error | since=c++11 | | + | {{ddcl|header=system_error|since=c++11| |
const std::error_category& generic_category() noexcept; | const std::error_category& generic_category() noexcept; | ||
}} | }} | ||
Line 15: | Line 15: | ||
===Example=== | ===Example=== | ||
{{example | {{example | ||
− | + | |code= | |
− | + | ||
− | + | ||
− | + | ||
#include <cerrno> | #include <cerrno> | ||
+ | |||
#include <string> | #include <string> | ||
+ | |||
+ | |||
int main() | int main() | ||
{ | { | ||
Line 28: | Line 28: | ||
<< "Message: " << econd.message() << '\n'; | << "Message: " << econd.message() << '\n'; | ||
} | } | ||
− | + | |output= | |
Category: generic | Category: generic | ||
Value: 33 | Value: 33 | ||
Line 36: | Line 36: | ||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc inc | cpp/error/dsc system_category}} | + | {{dsc inc|cpp/error/dsc system_category}} |
− | {{dsc inc | cpp/error/dsc errc}} | + | {{dsc inc|cpp/error/dsc errc}} |
{{dsc end}} | {{dsc end}} | ||
− | + | deesfritjaptruzh | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
Latest revision as of 01:23, 1 September 2023
Defined in header <system_error>
|
||
const std::error_category& generic_category() noexcept; |
(since C++11) | |
Obtains a reference to the static error category object for generic errors. The object is required to override the virtual function error_category::name() to return a pointer to the string "generic". It is used to identify error conditions that correspond to the POSIX errno codes.
Contents |
[edit] Parameters
(none)
[edit] Return value
A reference to the static object of unspecified runtime type, derived from std::error_category.
[edit] Example
Run this code
#include <cerrno> #include <iostream> #include <string> #include <system_error> int main() { std::error_condition econd = std::generic_category().default_error_condition(EDOM); std::cout << "Category: " << econd.category().name() << '\n' << "Value: " << econd.value() << '\n' << "Message: " << econd.message() << '\n'; }
Output:
Category: generic Value: 33 Message: Numerical argument out of domain
[edit] See also
(C++11) |
identifies the operating system error category (function) |
(C++11) |
the std::error_condition enumeration listing all standard <cerrno> macro constants (class) |