File tree 2 files changed +46
-12
lines changed 2 files changed +46
-12
lines changed Original file line number Diff line number Diff line change @@ -35,15 +35,20 @@ namespace Json {
35
35
36
36
/* * Base class for all exceptions we throw.
37
37
*/
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);
47
52
48
53
/* * \brief Type of the value held by a Value object.
49
54
*/
Original file line number Diff line number Diff line change @@ -152,17 +152,46 @@ static inline void releaseStringValue(char* value) { free(value); }
152
152
153
153
namespace Json {
154
154
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
+
155
172
Exception::Exception (std::string const & msg)
156
173
: msg_(msg)
157
- , future_use_(NULL )
158
- {
159
- }
174
+ {}
160
175
Exception::~Exception () throw ()
161
176
{}
162
177
char const * Exception::what () const throw()
163
178
{
164
179
return msg_.c_str ();
165
180
}
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
+ }
166
195
167
196
// //////////////////////////////////////////////////////////////////
168
197
// //////////////////////////////////////////////////////////////////
You can’t perform that action at this time.
0 commit comments