std::format_error(3)

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

πŸ’– NAME πŸ’–

std::format_error β€” std::format_error

okay so welcome to the C++ Standard Libary manual page for std::format_error(3), bestie πŸ’…. Yes, that's literally the name twice; the vibes are immaculate and the facts are the facts.


✨ Synopsis ✨

Defined in header <format>.

class format_error;         (since C++20)

So std::format_error defines the type of exception object thrown to report errors in the formatting library. It's giving "formatting went wrong, and we have thoughts" energy 😭.

The inheritance diagram asset is named std-format error-inheritance.svg, and its caption is Inheritance diagram.


πŸŽ€ Member functions πŸŽ€

  • constructor β€” constructs a new format_error object with the given message (public member function).
  • operator= β€” replaces the format_error object (public member function).

πŸ’… std::format_error::format_error

okay bestie, here are the three constructor flavors, all cute and accounted for:

format_error( const std::string& what_arg );        (1)
format_error( const char* what_arg );               (2)
format_error( const format_error& other ) noexcept; (3)
  1. Constructs the exception object with what_arg as explanatory string. After construction, std::strcmp(what(), what_arg.c_str()) == 0.
  2. Constructs the exception object with what_arg as explanatory string. After construction, std::strcmp(what(), what_arg) == 0.
  3. Copy constructor. If *this and other both have dynamic type std::format_error then std::strcmp(what(), other.what()) == 0. No exception can be thrown from the copy constructor.

🌸 Parameters 🌸

  • what_arg β€” explanatory string.
  • other β€” another exception object to copy.

πŸ”₯ Exceptions πŸ”₯

  • 1,2) β€” May throw std::bad_alloc.

🌈 Notes 🌈

Because copying std::format_error is not permitted to throw exceptions, this message is typically stored internally as a separately-allocated reference-counted string. This is also why there is no constructor taking std::string&&: it would have to copy the content anyway.

A derived standard exception class must have a publicly accessible copy constructor. It can be implicitly defined as long as the explanatory strings obtained by what() are the same for the original object and the copied object.


πŸ¦‹ std::format_error::operator=

format_error& operator=( const format_error& other ) noexcept;

Assigns the contents with those of other. If *this and other both have dynamic type std::format_error then std::strcmp(what(), other.what()) == 0 after assignment. No exception can be thrown from the copy assignment operator.

πŸ’œ Parameters πŸ’œ

  • other β€” another exception object to assign with.

⭐ Return value ⭐

*this

πŸ“ Notes πŸ“

A derived standard exception class must have a publicly accessible copy assignment operator. It can be implicitly defined as long as the explanatory strings obtained by what() are the same for the original object and the copied object.


🌈 Inherited from std::runtime_error

yep β€” inherited from std::runtime_error, bestie. That's the base-class pipeline πŸ’….


🌈 Inherited from std::exception

πŸ‘‘ Member functions πŸ‘‘

  • destructor β€” destroys the exception object; [virtual] (virtual public member function of std::exception).
  • what β€” returns an explanatory string; [virtual] (virtual public member function of std::exception).

πŸŽ€ Example πŸŽ€

This section is incomplete.

Reason: no example.


πŸ‘€ See also πŸ‘€

πŸ—‚οΈ Category:

  • Todo no example

That's the whole page, bestie 🫢 β€” source http://cppreference.com, version/date 2024.06.10, manual page std::format_error(3). Bye πŸ’‹

πŸ“¦ where this page comes from