std::exception::exception(3)

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

πŸ’… std::exception::exception(3) πŸ’…

okay bestie, welcome to the std::exception::exception page β€” manual name: C++ Standard Libary (yep, that's literally the spelling on the page, we're not touching it πŸ’–). This is your C++ exception-constructor moment, and it's lowkey iconic.

✨ NAME ✨

std::exception::exception - std::exception::exception

🌈 Synopsis 🌈

exception() throw();                                  (until C++11)
exception() noexcept;                         (1)     (since C++11)
exception( const exception& other ) throw();      (2)
(until C++11)
exception( const exception& other ) noexcept;
(since C++11)

It constructs a new exception object. That's the whole assignment, no cap.

  1. Default constructor. what() returns an implementation-defined string.
  2. Copy constructor. Initializes the contents with those of other. If *this and other both have dynamic type std::exception, then std::strcmp(what(), other.what()) == 0.

πŸŽ€ Parameters πŸŽ€

  • other β€” another exception to assign the contents of.

πŸ’œ Notes πŸ’œ

okay so here's the tea: copying std::exception is not permitted to throw exceptions. Because of that, when derived classes (such as std::runtime_error) have to manage a user-defined diagnostic message, it is typically implemented as a copy-on-write string. That's the standard move, fr fr.

The Microsoft implementation includes non-standard constructors taking strings, thus allowing instances to be thrown directly with a meaningful error message. The nearest standard equivalents are std::runtime_error or std::logic_error. Slay for convenience, but stay standard if you can 🫢.

πŸ› Defect reports πŸ›

The following behavior-changing defect reports were applied retroactively to previously published C++ standards:

  • DR: LWG 471 β€” applied to: C++98; behavior as published: "there is no requirement on what() of the exception copy"; correct behavior: added β€” the requirement on what() of the exception copy got added.

source: cppreference.com Β· version/date: 2024.06.10 β€” that's the footer, bestie, and we're signing off with a sparkle πŸŽ€βœ¨πŸ’–

πŸ“¦ where this page comes from