File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,15 +35,20 @@ namespace Json {
3535
3636/* * Base class for all exceptions we throw.
3737 */
38- class Exception : public std ::exception {
39- public:
40- Exception (std::string const & msg);
41- virtual ~Exception () throw ();
42- virtual char const * what () const throw();
43- protected:
44- std::string const & msg_;
45- void * future_use_;
46- };
38+ class JSON_API Exception;
39+ /* * Exceptions which the user cannot easily avoid.
40+ *
41+ * E.g. out-of-memory, stack-overflow, malicious input
42+ */
43+ class JSON_API RuntimeError;
44+ /* * Exceptions throw by JSON_ASSERT/JSON_FAIL macros.
45+ *
46+ * These are precondition-violations (user bugs) and internal errors (our bugs).
47+ */
48+ class JSON_API LogicError;
49+
50+ JSON_API void throwRuntimeError (std::string const & msg);
51+ JSON_API void throwLogicError (std::string const & msg);
4752
4853/* * \brief Type of the value held by a Value object.
4954 */
Original file line number Diff line number Diff line change @@ -152,17 +152,46 @@ static inline void releaseStringValue(char* value) { free(value); }
152152
153153namespace Json {
154154
155+ class JSON_API Exception : public std::exception {
156+ public:
157+ Exception (std::string const & msg);
158+ virtual ~Exception () throw ();
159+ virtual char const * what () const throw();
160+ protected:
161+ std::string const & msg_;
162+ };
163+ class JSON_API RuntimeError : public Exception {
164+ public:
165+ RuntimeError (std::string const & msg);
166+ };
167+ class JSON_API LogicError : public Exception {
168+ public:
169+ LogicError (std::string const & msg);
170+ };
171+
155172Exception::Exception (std::string const & msg)
156173 : msg_(msg)
157- , future_use_(NULL )
158- {
159- }
174+ {}
160175Exception::~Exception () throw ()
161176{}
162177char const * Exception::what () const throw()
163178{
164179 return msg_.c_str ();
165180}
181+ RuntimeError::RuntimeError (std::string const & msg)
182+ : Exception(msg)
183+ {}
184+ LogicError::LogicError (std::string const & msg)
185+ : Exception(msg)
186+ {}
187+ void throwRuntimeError (std::string const & msg)
188+ {
189+ throw RuntimeError (msg);
190+ }
191+ void throwLogicError (std::string const & msg)
192+ {
193+ throw LogicError (msg);
194+ }
166195
167196// //////////////////////////////////////////////////////////////////
168197// //////////////////////////////////////////////////////////////////
You can’t perform that action at this time.
0 commit comments