std::system_category(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

okay bestie, buckle up: this is std::system_category(3) from the C++ Standard Libary (yes, that's the manual name, and yes, we're keeping it exactly like that πŸ’…).

🌈 NAME 🌈

  • std::system_category β€” the std::system_category function, no cap. That's the whole name, and we're moving on. πŸ¦‹

✨ Synopsis ✨

Defined in header <system_error>.

const std::error_category& system_category() noexcept;

(since C++11) β€” she's been iconic since then, periodt.

Okay so this obtains a reference to the static error category object for errors reported by the operating system. The object is required to override the virtual function std::error_category::name() to return a pointer to the string "system". It is also required to override the virtual function std::error_category::default_error_condition() to map the error codes that match POSIX errno values to std::generic_category.

πŸŽ€ Parameters πŸŽ€

(none) β€” literally none, bestie. Not a single parameter. πŸ’€

πŸ’– Return value πŸ’–

A reference to the static object of unspecified runtime type, derived from std::error_category.

πŸ¦‹ Notes πŸ¦‹

On Windows, system_category() typically maps some Windows error codes to POSIX ones. On POSIX, system_category() tends to be equivalent to std::generic_category() except for the name.

🌸 Example 🌸

// Run this code

#include <iomanip>
#include <iostream>
#include <string>
#include <system_error>

int main()
{
    for (int const code : {EDOM, 10001})
    {
        const std::error_condition econd =
            std::system_category().default_error_condition(code);

        std::cout << "Category: " << econd.category().name() << '\n'
                  << "Value:    " << econd.value() << '\n'
                  << "Message:  " << econd.message() << "\n\n";
    }
}

Possible output:

Category: generic
Value:    33
Message:  Numerical argument out of domain

Category: system
Value:    10001
Message:  Unknown error 10001

πŸ‘‘ See also πŸ‘‘

  • generic_category β€” identifies the generic error category. (function, (C++11))
  • errc β€” the std::error_condition enumeration listing all standard <cerrno> macro constants. (class, (C++11))

and that's the whole page, bestie 🫢 source/version/date vibes: http://cppreference.com, 2024.06.10, and the title is std::system_category(3). byeee πŸ’…βœ¨

πŸ“¦ where this page comes from