Skip to content

Commit 83cc921

Browse files
baylesjcdunn2001
authored andcommitted
Fix JSON_USE_EXCEPTION=0 use case
This patch fixes the JSON_USE_EXCEPTION flag. Currently, due to the throwRuntimeError and throwLogicError methods implemented in json_value, even if JSON_USE_EXCEPTION is set to 0 jsoncpp will still throw. This breaks integration into projects with -fno-exceptions set, such as Chromium.
1 parent 5b91551 commit 83cc921

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Diff for: include/json/value.h

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
*/
5151
namespace Json {
5252

53+
#if JSON_USE_EXCEPTION
5354
/** Base class for all exceptions we throw.
5455
*
5556
* We use nothing but these internally. Of course, STL can throw others.
@@ -85,6 +86,7 @@ class JSON_API LogicError : public Exception {
8586
public:
8687
LogicError(String const& msg);
8788
};
89+
#endif
8890

8991
/// used internally
9092
JSONCPP_NORETURN void throwRuntimeError(String const& msg);

Diff for: src/lib_json/json_value.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ static inline void releaseStringValue(char* value, unsigned) { free(value); }
226226

227227
namespace Json {
228228

229+
#if JSON_USE_EXCEPTION
229230
Exception::Exception(String msg) : msg_(std::move(msg)) {}
230231
Exception::~Exception() JSONCPP_NOEXCEPT {}
231232
char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); }
@@ -237,6 +238,14 @@ JSONCPP_NORETURN void throwRuntimeError(String const& msg) {
237238
JSONCPP_NORETURN void throwLogicError(String const& msg) {
238239
throw LogicError(msg);
239240
}
241+
# else // !JSON_USE_EXCEPTION
242+
JSONCPP_NORETURN void throwRuntimeError(String const& msg) {
243+
abort();
244+
}
245+
JSONCPP_NORETURN void throwLogicError(String const& msg) {
246+
abort();
247+
}
248+
#endif
240249

241250
// //////////////////////////////////////////////////////////////////
242251
// //////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)