---
name: "std::error_code"
section: "3"
platform: "linux"
package: "gcc"
version: "16.2.1+r23+gd564253eb6c8-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/std::error_code"
---

# std::error\_code(3)

## NAME

std::error\_code

## SYNOPSIS

\#include \<system\_error\>

### Public Member Functions

template\<typename \_ErrorCodeEnum, typename = \_Check\<\_ErrorCodeEnum\>\> **error\_code** (\_ErrorCodeEnum \_\_e) noexcept\
 Initialize with a user-defined type, by calling make\_error\_code.  **error\_code** (const error\_code &)=default\
 **error\_code** (int \_\_v, const **error\_category** &\_\_cat) noexcept\
 void **assign** (int \_\_v, const **error\_category** &\_\_cat) noexcept\
 const **error\_category** & **category** () const noexcept\
 The error category that this error belongs to.  void **clear** () noexcept\
 **error\_condition** **default\_error\_condition** () const noexcept\
 An error\_condition for this error's category and value.  **string** **message** () const\
 The category's description of the value.  **operator bool** () const noexcept\
 Test whether value() is non-zero.  error\_code & **operator=** (const error\_code &)=default\
 int **value** () const noexcept\
 The error value.

### Related Symbols

(Note that these are not member symbols.)  error\_code **make\_error\_code** (errc \_\_e) noexcept\
 template\<typename \_CharT, typename \_Traits\> **basic\_ostream**\< \_CharT, \_Traits \> & **operator\<\<** (**basic\_ostream**\< \_CharT, \_Traits \> &\_\_os, const error\_code &\_\_e)\
 strong\_ordering **operator\<=\>** (const error\_code &\_\_lhs, const error\_code &\_\_rhs) noexcept\

## Detailed Description

Class error\_code

This class is a value type storing an integer error number and a category that gives meaning to the error number. Typically this is done close the the point where the error happens, to capture the original error value.

An error\_code object can be used to store the original error value emitted by some subsystem, with a category relevant to the subsystem. For example, errors from POSIX library functions can be represented by an errno value and the "generic" category, but errors from an HTTP library might be represented by an HTTP response status code (e.g. 404) and a custom category defined by the library.

**Since**

C++11

## Constructor & Destructor Documentation

### template\<typename \_ErrorCodeEnum, typename = \_Check\<\_ErrorCodeEnum\>\> std::error\_code::error\_code (\_ErrorCodeEnum \_\_e) \[inline\], \[noexcept\]

Initialize with a user-defined type, by calling make\_error\_code.

References **make\_error\_code()**.

## Member Function Documentation

### const error\_category & std::error\_code::category () const \[inline\], \[noexcept\]

The error category that this error belongs to.

Referenced by **message()**.

### error\_condition std::error\_code::default\_error\_condition () const \[noexcept\]

An error\_condition for this error's category and value.

### string std::error\_code::message () const \[inline\]

The category's description of the value.

References **category()**, **std::error\_category::message()**, **message()**, and **value()**.

Referenced by **message()**.

### std::error\_code::operator bool () const \[inline\], \[explicit\], \[noexcept\]

Test whether value() is non-zero.

### int std::error\_code::value () const \[inline\], \[noexcept\]

The error value.

Referenced by **message()**.

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
