public member function
<system_error>

std::error_code::error_code

(1)
error_code() noexcept;
(2)
error_code (int val, const error_category& cat) noexcept;
(3)
template <class ErrorCodeEnum>
  error_code (ErrorCodeEnum e) noexcept;
Construct error_code
Constructs an error_code object:
default constructor (1)
Error code with a value of 0 of the system_category (generally indicating no error).
initialization constructor (2)
Error code with a value of val of the category specified by cat.
construct from error code enum type (3)
Calls make_error_code to construct an error code.
This constructor only participates in overload resolution if is_error_code_enum<ErrorCodeEnum>::value is true.

Parameters

val
A numerical value identifying an error code.
cat
A reference to an error_category object.
e
Error code enum value of an enum type for which is_error_code_enum has a value member with a value of true.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// error_code constructors
#include <iostream>       // std::cout
#include <cmath>          // std::sqrt
#include <cerrno>         // errno
#include <system_error>   // std::error_code, std::generic_category
                          // std::error_condition
int main()
{
  errno=0;
  std::sqrt(-1.0);        // errno set to EDOM
  std::error_code ec (errno,std::generic_category());

  std::error_condition ok;
  if (ec != ok) std::cout << "Error: " << ec.message() << '\n';

  return 0;
}


Possible output (cout):
Error: Domain error

See also