std::nested_exception(3cxx)

πŸ’… std::nested_exception

okay bestie, welcome to the cxx corner of the manual β€” this page is literally called std::nested_exception, and it's about to become your new hyperfixation. it's a mixin class, it's C++11, it's giving "small but essential." let's get into it 🫢


✨ SYNOPSIS ✨

first things first, you gotta let it in:

#include <exception>

πŸŽ€ Public Member Functions

  • nested_exception () noexcept β€” the default constructor, and she stores the current exception (if any). no cap, that's the whole job πŸ’…
  • nested_exception (const nested_exception &) noexcept=default β€” copy constructor, defaulted and noexcept, iconic behaviour only
  • exception_ptr nested_ptr () const noexcept β€” access the stored exception, that's it, that's the vibe
  • nested_exception & operator= (const nested_exception &) noexcept=default β€” copy assignment, also defaulted, also noexcept, also slaying
  • void rethrow_nested () const β€” rethrow the stored exception, or terminate if none was stored 😭 (yes, for real, please note that)

🌸 Detailed Description 🌸

so, mixin class that stores the current exception. that's the assignment, and she ate ✨

you use this type via std::throw_with_nested to store the current exception nested within another exception. it's like a little exception inside an exception, matryoshka doll energy, main character and supporting cast πŸͺ†πŸ’œ

Since: C++11 β€” old enough to be trusted, young enough to be relevant πŸ’…

See also: std::throw_with_nested β€” her bestie, her partner in crime, go read that one next 🫢


πŸ¦‹ Constructor & Destructor Documentation πŸ¦‹

std::nested_exception::nested_exception () [inline], [noexcept]

the default constructor. she stores the current exception (if any). if there isn't one, cool, she just vibes. no drama, noexcept girlies don't panic 🌈


πŸ‘‘ Member Function Documentation πŸ‘‘

exception_ptr std::nested_exception::nested_ptr () const [inline], [noexcept]

access the stored exception. that's it. get your exception_ptr, live your life, it's literally that simple πŸŽ€

void std::nested_exception::rethrow_nested () const [inline]

rethrow the stored exception, or terminate if none was stored πŸ’€ this is not a drill, this is the documented behaviour, so check before you call fr fr.

References std::rethrow_exception() and std::terminate() β€” both linked, both important, iykyk ⭐


bestie note: rethrow_nested() straight-up calls std::terminate() when nothing was stored. that's a whole program-ending moment, so don't roll up unprepared πŸ™ˆ

🧚 Author 🧚

generated automatically by Doxygen for libstdc++ from the source code. not me being auto-generated and still having more personality than half the headers out here πŸ’…βœ¨


and that's the page, bestie! sign-off time: this little gem is from libstdc++, manual page std::nested_exception(3cxx) β€” go forth and nest your exceptions responsibly πŸ¦‹πŸ“πŸ’–

πŸ“¦ where this page comes from