std::exception(3)

πŸ’– std::exception β€” NAME πŸ’–

std::exception β€” the base class for all library exceptions. Like, the OG. The mother of every throw you've ever panic-written at 3am. This page lives in the Library Functions Manual section (3), iykyk 🫢


✨ SYNOPSIS ✨

#include <exception>

🌸 Inherited by

Bestie, the docs literally list these as inherited-by, and four of the entries came through completely blank in the source β€” so here's exactly what's there, gaps and all:

  • (blank)
  • (blank)
  • (blank)
  • (blank)
  • __gnu_cxx::forced_error
  • __gnu_cxx::recursive_init_error
  • std::bad_alloc
  • std::bad_cast
  • std::bad_exception
  • std::bad_function_call

πŸŽ€ Public Member Functions

  • _GLIBCXX26_CONSTEXPR exception(const exception &)=default β€” copy constructor, defaulted, no notes πŸ’…
  • _GLIBCXX26_CONSTEXPR exception(exception &&)=default β€” move constructor, also defaulted, also iconic
  • _GLIBCXX26_CONSTEXPR exception & operator=(const exception &)=default β€” copy assignment, defaulted
  • _GLIBCXX26_CONSTEXPR exception & operator=(exception &&)=default β€” move assignment, defaulted
  • virtual constexpr const char * what() const noexcept β€” the one member function that actually does something πŸ¦‹

πŸ‘‘ Detailed Description πŸ‘‘

Base class for all library exceptions.

Okay so real talk: this is the base class for all exceptions thrown by the standard library, and by certain language expressions. That's a lot of responsibility for one little class. Main character energy, honestly.

And here's the freeing part β€” you are free to:

  • derive your own exception classes πŸŽ€
  • use a different hierarchy entirely (go off, build your own kingdom) 🏰
  • throw non-class data (like, e.g., fundamental types) 😭

No cap, the standard library is not the boss of you.


πŸ”₯ Member Function Documentation πŸ”₯

⭐ virtual constexpr const char * std::exception::what() const [inline], [constexpr], [virtual], [noexcept]

Returns a C-style character string describing the general cause of the current error. That's it, that's the job. It's giving "explain yourself in C-string form" πŸ’€

Reimplemented in:

  • std::bad_alloc
  • std::bad_cast
  • std::bad_exception
  • std::bad_function_call
  • std::bad_typeid
  • std::bad_weak_ptr
  • std::experimental::filesystem::v1::filesystem_error
  • std::experimental::fundamentals_v1::bad_any_cast
  • std::filesystem::filesystem_error
  • std::future_error
  • std::ios_base::failure
  • std::logic_error
  • std::runtime_error
Lowkey every single one of them said "not me inheriting what() and doing nothing with it" and then went and overrode it anyway. Respect. 🫢

🌈 Author 🌈

Generated automatically by Doxygen for libstdc++ from the source code. Not a human, just a very diligent robot ✨


And that's the whole page, bestie β€” footer said libstdc++ (that's the source/version, courtesy of the libstdc++ manual itself, with the standard std::exception(3) running header up top). No date on this one, so don't come for me. Study it, love it, override what() responsibly. Periodt. πŸ’…πŸŽ€πŸ’–

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms