mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-03-13 06:01:45 +00:00
util: Throw tinyformat::format_error on formatting error
Throw tinyformat::format_error on formatting error instead of the `std::runtime_error`.
This commit is contained in:
parent
3b092bd9b6
commit
b651270cd6
@ -123,7 +123,7 @@ namespace tinyformat {}
|
|||||||
namespace tfm = tinyformat;
|
namespace tfm = tinyformat;
|
||||||
|
|
||||||
// Error handling; calls assert() by default.
|
// Error handling; calls assert() by default.
|
||||||
#define TINYFORMAT_ERROR(reasonString) throw std::runtime_error(reasonString)
|
#define TINYFORMAT_ERROR(reasonString) throw tinyformat::format_error(reasonString)
|
||||||
|
|
||||||
// Define for C++11 variadic templates which make the code shorter & more
|
// Define for C++11 variadic templates which make the code shorter & more
|
||||||
// general. If you don't define this, C++11 support is autodetected below.
|
// general. If you don't define this, C++11 support is autodetected below.
|
||||||
@ -164,6 +164,13 @@ namespace tfm = tinyformat;
|
|||||||
|
|
||||||
namespace tinyformat {
|
namespace tinyformat {
|
||||||
|
|
||||||
|
class format_error: public std::runtime_error
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
format_error(const std::string &what): std::runtime_error(what) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ template<typename... Args> std::string FormatStringFromLogArgs(const char *fmt,
|
|||||||
std::string _log_msg_; /* Unlikely name to avoid shadowing variables */ \
|
std::string _log_msg_; /* Unlikely name to avoid shadowing variables */ \
|
||||||
try { \
|
try { \
|
||||||
_log_msg_ = tfm::format(__VA_ARGS__); \
|
_log_msg_ = tfm::format(__VA_ARGS__); \
|
||||||
} catch (std::runtime_error &e) { \
|
} catch (tinyformat::format_error &e) { \
|
||||||
/* Original format string will have newline so don't add one here */ \
|
/* Original format string will have newline so don't add one here */ \
|
||||||
_log_msg_ = "Error \"" + std::string(e.what()) + "\" while formatting log message: " + FormatStringFromLogArgs(__VA_ARGS__); \
|
_log_msg_ = "Error \"" + std::string(e.what()) + "\" while formatting log message: " + FormatStringFromLogArgs(__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user