From 3a2115bcdcfbca0432afad84f4877187f72514a2 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Fri, 1 Sep 2023 00:28:41 -0400 Subject: Make asserts from jsoncpp more descriptive --- json/json.h | 16 ++++++++++------ json/jsoncpp.cpp | 5 +++-- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'json') diff --git a/json/json.h b/json/json.h index da91470a..399de6ca 100644 --- a/json/json.h +++ b/json/json.h @@ -502,6 +502,12 @@ public: #pragma warning(disable : 4251) #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) +// XXX: BN: Use our exception class for extra details +#include "../exceptions.h" +#define JSONCPP_EXCEPTION ExceptionWithStackTrace +// #define JSONCPP_EXCEPTION std::runtime_error + + #pragma pack(push, 8) /** \brief JSON (JavaScript Object Notation). @@ -512,14 +518,12 @@ namespace Json { * * We use nothing but these internally. Of course, STL can throw others. */ -class JSON_API Exception : public std::exception { +class JSON_API Exception : public JSONCPP_EXCEPTION /* BN: subclass changed */ { public: Exception(JSONCPP_STRING const& msg); ~Exception() JSONCPP_NOEXCEPT JSONCPP_OVERRIDE; - char const* what() const JSONCPP_NOEXCEPT JSONCPP_OVERRIDE; - -protected: - JSONCPP_STRING msg_; + // BN: Member removed + // BN: what() removed }; /** Exceptions which the user cannot easily avoid. @@ -2222,7 +2226,7 @@ JSON_API JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM&, const Value& root); #define JSON_ASSERT(condition) \ { \ if (!(condition)) { \ - Json::throwLogicError("assert json failed"); \ + Json::throwLogicError(#condition); \ } \ } diff --git a/json/jsoncpp.cpp b/json/jsoncpp.cpp index 4154200b..307cf560 100644 --- a/json/jsoncpp.cpp +++ b/json/jsoncpp.cpp @@ -2653,9 +2653,10 @@ static inline void releaseStringValue(char* value, unsigned) { free(value); } namespace Json { -Exception::Exception(JSONCPP_STRING const& msg) : msg_(msg) {} +// BN: subclass +Exception::Exception(JSONCPP_STRING const& msg) : JSONCPP_EXCEPTION(msg) {} Exception::~Exception() JSONCPP_NOEXCEPT {} -char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); } +// BN: removed what() RuntimeError::RuntimeError(JSONCPP_STRING const& msg) : Exception(msg) {} LogicError::LogicError(JSONCPP_STRING const& msg) : Exception(msg) {} JSONCPP_NORETURN void throwRuntimeError(JSONCPP_STRING const& msg) { -- cgit v1.3.1