From 67982f3963a5211d302bb4bf108e59e97bc357ab Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Mon, 24 Mar 2025 16:57:54 -0500 Subject: [PATCH] Base: Add Console::DestructorError as noexcept Create a new console output that eats exceptions so it is safe to use in a destructor. --- src/Base/Console.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Base/Console.h b/src/Base/Console.h index e377c2d904..6e3a6e66b8 100644 --- a/src/Base/Console.h +++ b/src/Base/Console.h @@ -26,6 +26,7 @@ // Std. configurations #include +#include #include #include #include @@ -759,6 +760,11 @@ public: template inline void DeveloperError(const std::string& notifier, const char* pMsg, Args&&... args); template + /// A noexcept DeveloperError for use in destructors. When compiled in debug, terminates via an + /// assert. In release, the exception is silently caught and dropped. + inline void + DestructorError(const std::string& notifier, const char* pMsg, Args&&... args) noexcept; + template inline void UserError(const std::string& notifier, const char* pMsg, Args&&... args); template inline void TranslatedUserError(const std::string& notifier, const char* pMsg, Args&&... args); @@ -1083,6 +1089,21 @@ inline void Base::ConsoleSingleton::DeveloperError(const std::string& notifier, Base::ContentType::Untranslatable>(notifier, pMsg, std::forward(args)...); } +template +inline void Base::ConsoleSingleton::DestructorError(const std::string& notifier, + const char* pMsg, + Args&&... args) noexcept +{ + try { + Send(notifier, pMsg, std::forward(args)...); + } + catch (...) { + assert("An exception was thrown while attempting console output in a destructor" && false); + } +} + template inline void Base::ConsoleSingleton::UserError(const std::string& notifier, const char* pMsg, Args&&... args)