std::exception::exception(3)
π 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.
- Default constructor.
what()returns an implementation-defined string. - Copy constructor. Initializes the contents with those of
other. If*thisandotherboth have dynamic typestd::exception, thenstd::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 onwhat()of the exception copy"; correct behavior:addedβ the requirement onwhat()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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms