Base: Stop exception from leaking from Console().*

These are sometimes used in destructors, where a raised exception calls terminate()
This commit is contained in:
Chris Hennes
2025-02-20 22:01:31 -06:00
parent 45f913eb9e
commit 59f8649103
2 changed files with 13 additions and 2 deletions

View File

@@ -1169,7 +1169,17 @@ template<Base::LogStyle category,
inline void
Base::ConsoleSingleton::Send(const std::string& notifiername, const char* pMsg, Args&&... args)
{
std::string format = fmt::sprintf(pMsg, args...);
std::string format;
try {
format = fmt::sprintf(pMsg, args...);
}
catch (fmt::format_error& e) {
// We can't allow an exception to propagate out of this method, which gets used in some
// destructors. Instead, make the string's contents the error message that fmt::sprintf gave
// us.
format = std::string("ERROR: Invalid format string or arguments provided.\n");
format += e.what();
}
if (connectionMode == Direct) {
Notify<category, recipient, contenttype>(notifiername, format);

View File

@@ -24,6 +24,7 @@
#ifndef _PreComp_
#include <boost/tokenizer.hpp>
#include <boost/regex.hpp>
#include <deque>
#include <memory>
#include <sstream>
@@ -107,7 +108,7 @@ Sheet::~Sheet()
try {
clearAll();
}
catch (boost::wrapexcept<boost::regex_error>&) {
catch (boost::regex_error&) {
// Don't let an exception propagate out of a destructor (calls terminate())
Base::Console().Error(
"clearAll() resulted in an exception when deleting the spreadsheet : %s\n",