Skip to content

Commit b651270

Browse files
committed
util: Throw tinyformat::format_error on formatting error
Throw tinyformat::format_error on formatting error instead of the `std::runtime_error`.
1 parent 3b092bd commit b651270

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/tinyformat.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ namespace tinyformat {}
123123
namespace tfm = tinyformat;
124124

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

128128
// Define for C++11 variadic templates which make the code shorter & more
129129
// general. If you don't define this, C++11 support is autodetected below.
@@ -164,6 +164,13 @@ namespace tfm = tinyformat;
164164

165165
namespace tinyformat {
166166

167+
class format_error: public std::runtime_error
168+
{
169+
public:
170+
format_error(const std::string &what): std::runtime_error(what) {
171+
}
172+
};
173+
167174
//------------------------------------------------------------------------------
168175
namespace detail {
169176

src/util.h

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

0 commit comments

Comments
 (0)