public member function
<system_error>
(1) | error_condition() noexcept; |
---|
(2) | error_condition (int val, const error_category& cat) noexcept; |
---|
(3) | template <class ErrorConditionEnum> error_condition (ErrorConditionEnum e) noexcept; |
---|
Construct error_condition
Constructs an error_condition object:
- default constructor (1)
- Error condition with a value of
0
of the generic_category (associated with lack of error).
- initialization constructor (2)
- Error condition with a value of val of the category specified by cat.
- construct from error condition enum type (3)
- Calls make_error_condition to construct an error code.
This constructor only participates in overload resolution if is_error_condition_enum<ErrorConditionEnum>::value
is true
. Which is the case when errc is used as the ErrorConditionEnum type.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
// error_condition::error_condition
#include <iostream> // std::cout, std::ios
#include <system_error> // std::error_condition, std::generic_category
int main() {
std::cout << "The default error condition: ";
std::cout << std::error_condition().message() << '\n';
std::cout << "A condition constructed from errc: ";
std::cout << std::error_condition(std::errc::permission_denied).message() << '\n';
std::cout << "Some generic error conditions, by value:\n";
for (int i=0; i<10; ++i) {
std::error_condition c (i,std::generic_category());
std::cout << "\t#" << i << ": " << c.message() << '\n';
}
return 0;
}
|
Possible output:
The default error condition: No error
A condition constructed from errc: Permission denied
Some generic error conditions, by value:
#0: No error
#1: Operation not permitted
#2: No such file or directory
#3: No such process
#4: Interrupted function call
#5: Input/output error
#6: No such device or address
#7: Arg list too long
#8: Exec format error
#9: Bad file descriptor
|