Skip to content

Commit 949babd

Browse files
committed
Exceptions declared in header
resolves #272
1 parent 6ed877c commit 949babd

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

include/json/value.h

+18-3
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,36 @@ namespace Json {
3737
*
3838
* We use nothing but these internally. Of course, STL can throw others.
3939
*/
40-
class JSON_API Exception;
40+
class JSON_API Exception : public std::exception {
41+
public:
42+
Exception(std::string const& msg);
43+
virtual ~Exception() throw();
44+
virtual char const* what() const throw();
45+
protected:
46+
std::string const msg_;
47+
};
48+
4149
/** Exceptions which the user cannot easily avoid.
4250
*
4351
* E.g. out-of-memory (when we use malloc), stack-overflow, malicious input
4452
*
4553
* \remark derived from Json::Exception
4654
*/
47-
class JSON_API RuntimeError;
55+
class JSON_API RuntimeError : public Exception {
56+
public:
57+
RuntimeError(std::string const& msg);
58+
};
59+
4860
/** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
4961
*
5062
* These are precondition-violations (user bugs) and internal errors (our bugs).
5163
*
5264
* \remark derived from Json::Exception
5365
*/
54-
class JSON_API LogicError;
66+
class JSON_API LogicError : public Exception {
67+
public:
68+
LogicError(std::string const& msg);
69+
};
5570

5671
/// used internally
5772
void throwRuntimeError(std::string const& msg);

src/lib_json/json_value.cpp

-17
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,6 @@ static inline void releaseStringValue(char* value) { free(value); }
152152

153153
namespace 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-
172155
Exception::Exception(std::string const& msg)
173156
: msg_(msg)
174157
{}

0 commit comments

Comments
 (0)