Skip to content

Commit 318d6e1

Browse files
committed
Base: Stop exception from leaking from Console().*
These are sometimes used in destructors, where a raised exception calls terminate()
1 parent 9c097eb commit 318d6e1

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/Base/Console.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,17 @@ template<Base::LogStyle category,
11691169
inline void
11701170
Base::ConsoleSingleton::Send(const std::string& notifiername, const char* pMsg, Args&&... args)
11711171
{
1172-
std::string format = fmt::sprintf(pMsg, args...);
1172+
std::string format;
1173+
try {
1174+
format = fmt::sprintf(pMsg, args...);
1175+
}
1176+
catch (fmt::format_error& e) {
1177+
// We can't allow an exception to propagate out of this method, which gets used in some
1178+
// destructors. Instead, make the string's contents the error message that fmt::sprintf gave
1179+
// us.
1180+
format = std::string("ERROR: Invalid format string or arguments provided.\n");
1181+
format += e.what();
1182+
}
11731183

11741184
if (connectionMode == Direct) {
11751185
Notify<category, recipient, contenttype>(notifiername, format);

src/Mod/Spreadsheet/App/Sheet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#ifndef _PreComp_
2626
#include <boost/tokenizer.hpp>
27+
#include <boost/regex.hpp>
2728
#include <deque>
2829
#include <memory>
2930
#include <sstream>
@@ -107,7 +108,7 @@ Sheet::~Sheet()
107108
try {
108109
clearAll();
109110
}
110-
catch (boost::wrapexcept<boost::regex_error>&) {
111+
catch (boost::regex_error&) {
111112
// Don't let an exception propagate out of a destructor (calls terminate())
112113
Base::Console().Error(
113114
"clearAll() resulted in an exception when deleting the spreadsheet : %s\n",

0 commit comments

Comments
 (0)