---
name: "std::error_code"
section: "3cxx"
platform: "linux"
package: "libstdc++-12-doc"
version: "12.4.0-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/std::error_code/3cxx"
---

# std::error\_code(3cxx)

## NAME

std::error\_code

## SYNOPSIS

`#include <system_error>`

### Public Member Functions

template\<**typename** **\_ErrorCodeEnum** , **typename**  = typename enable\_if\<is\_error\_code\_enum\<\_ErrorCodeEnum\>::value\>::type\> **error\_code** (**\_ErrorCodeEnum** \_\_e) noexcept\
 **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.  template\<**typename** **\_ErrorCodeEnum** \> **enable\_if**\< **is\_error\_code\_enum**\< **\_ErrorCodeEnum** \>**::value**, **error\_code** & \>::type **operator=** (**\_ErrorCodeEnum** \_\_e) noexcept\
 int **value** () const noexcept\
 The error value.

### Related Symbols

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

## 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

## Member Function Documentation

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

The error category that this error belongs to.

### 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.

### 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.

## Author

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