std::error_code(3)

πŸ’– NAME πŸ’–

std::error_code β€” the little value-type bestie that carries an error number and the category that tells you what that number actually means 🫢


✨ SYNOPSIS ✨

#include <system_error>

🌸 Public Member Functions 🌸

  • template<typename _ErrorCodeEnum, typename = _Check<_ErrorCodeEnum>> error_code (_ErrorCodeEnum __e) noexcept β€” spin one up from your own user-defined type, by calling make_error_code πŸ’«
  • error_code (const error_code &)=default β€” copy ctor, defaulted, no drama
  • error_code (int __v, const error_category &__cat) noexcept β€” build it from a raw value plus a category
  • void assign (int __v, const error_category &__cat) noexcept β€” reassign the value and the category
  • const error_category & category () const noexcept β€” the error category this error belongs to 🏷️
  • void clear () noexcept β€” wipe it clean
  • 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 β€” tests whether value() is non-zero (so yes, it's the "do I have a problem" check πŸ‘€)
  • error_code & operator= (const error_code &)=default β€” assignment, defaulted
  • int value () const noexcept β€” the error value itself πŸ”’
bestie, heads up: these are not member symbols, they just hang out in the same neighborhood πŸ’…
  • 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

Okay so this class is a value type that stores an integer error number and a category, and the category is what gives that number meaning. Usually you do this right at the spot where the error actually happens, so you capture the original error value before it gets lost in the sauce 😭

An error_code object can hold the original error value that some subsystem spat out, together with a category that's relevant to that 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 (like 404) and a custom category that the library defines. Same energy, different category ✨

Since: C++11 β€” she's been iconic for a minute πŸ‘‘


πŸŽ€ 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. That's the whole move 🫢

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. It's giving "which flavor of problem is this" 🏷️

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. Basically the category translating the number for you πŸ’¬

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. Non-zero means yes there's an error, zero means we're chill 🌸

int std::error_code::value () const [inline], [noexcept]

The error value. The raw number. The receipts πŸ”’

Referenced by message().


πŸ‘‘ Author πŸ‘‘

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


and that's the whole page bestie πŸ’– generated by Doxygen for libstdc++, and yes, std::error_code(3) said what it said. no cap, go handle your errors. periodt βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.0.1-0.10.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms