Skip to content

Commit 9fb0a43

Browse files
committed
util: Throw tinyformat::format_error on formatting error
backports bitcoin/bitcoin@b651270
1 parent 67eb699 commit 9fb0a43

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/tinyformat.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ namespace tinyformat
125125
namespace tfm = tinyformat;
126126

127127
// Error handling; calls assert() by default.
128-
#define TINYFORMAT_ERROR(reasonString) throw std::runtime_error(reasonString)
128+
#define TINYFORMAT_ERROR(reasonString) throw tinyformat::format_error(reasonString)
129129

130130
// Define for C++11 variadic templates which make the code shorter & more
131131
// general. If you don't define this, C++11 support is autodetected below.
@@ -166,6 +166,14 @@ namespace tfm = tinyformat;
166166

167167
namespace tinyformat
168168
{
169+
170+
class format_error: public std::runtime_error
171+
{
172+
public:
173+
format_error(const std::string &what): std::runtime_error(what) {
174+
}
175+
};
176+
169177
//------------------------------------------------------------------------------
170178
namespace detail
171179
{

src/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ template<typename... Args> std::string FormatStringFromLogArgs(const char *fmt,
6969
std::string _log_msg_; /* Unlikely name to avoid shadowing variables */ \
7070
try { \
7171
_log_msg_ = tfm::format(__VA_ARGS__); \
72-
} catch (std::runtime_error &e) { \
72+
} catch (tinyformat::format_error &e) { \
7373
/* Original format string will have newline so don't add one here */ \
7474
_log_msg_ = "Error \"" + std::string(e.what()) + "\" while formatting log message: " + FormatStringFromLogArgs(__VA_ARGS__); \
7575
} \

0 commit comments

Comments
 (0)