From 75279ccec2f62bbb1ebd6dc449039be1b13c94b8 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 8 Mar 2015 12:20:06 -0500 Subject: [PATCH] base Json::Exception --- include/json/value.h | 13 +++++++++++++ src/lib_json/json_value.cpp | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/json/value.h b/include/json/value.h index b752fb8..1cd6291 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -11,6 +11,7 @@ #endif // if !defined(JSON_IS_AMALGAMATION) #include #include +#include #ifndef JSON_USE_CPPTL_SMALLMAP #include @@ -32,6 +33,18 @@ */ namespace Json { +/** Base class for all exceptions we throw. + */ +class Exception : public std::exception { +public: + Exception(std::string const& msg); + virtual ~Exception() throw(); + virtual char const* what() const throw(); +protected: + std::string const& msg_; + void* future_use_; +}; + /** \brief Type of the value held by a Value object. */ enum ValueType { diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 4e032ce..f7d2cde 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -152,6 +152,18 @@ static inline void releaseStringValue(char* value) { free(value); } namespace Json { +Exception::Exception(std::string const& msg) + : msg_(msg) + , future_use_(NULL) +{ +} +Exception::~Exception() throw() +{} +char const* Exception::what() const throw() +{ + return msg_.c_str(); +} + // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////