| 1 |
// © 2024 and later: Unicode, Inc. and others. |
| 2 |
// License & terms of use: http://www.unicode.org/copyright.html |
| 3 |
#ifndef __UJSON_H__ |
| 4 |
#define __UJSON_H__ |
| 5 |
|
| 6 |
/* |
| 7 |
Without this code, the output if the JSON library code |
| 8 |
throws an exception would look like: |
| 9 |
terminate called after throwing an instance of 'nlohmann::json_abi_v3_11_3::detail::parse_error' |
| 10 |
what(): [json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON |
| 11 |
Aborted (core dumped) |
| 12 |
|
| 13 |
(for example, if one of the JSON tests files contains an error or a file doesn't exist.) |
| 14 |
|
| 15 |
With this code, the output is: |
| 16 |
|
| 17 |
JSON exception thrown; modify tools/ctestfw//ujson.h to get diagnostics. |
| 18 |
Exiting immediately. |
| 19 |
|
| 20 |
The entire #if block can be commented out in order to temporarily enable exceptions |
| 21 |
and get a better parse error message (temporarily, while debugging). |
| 22 |
*/ |
| 23 |
|
| 24 |
// Disable exceptions in JSON parser |
| 25 |
|
| 26 |
#if _HAS_EXCEPTIONS == 0 |
| 27 |
#define JSON_TRY_USER if(true) |
| 28 |
#define JSON_CATCH_USER(exception) if(false) |
| 29 |
#define JSON_THROW_USER(exception) { \ |
| 30 |
printf("JSON exception thrown; modify tools/toolutil/ujson.h to get diagnostics.\n\ |
| 31 |
Exiting immediately.\n"); \ |
| 32 |
exit(1); \ |
| 33 |
} |
| 34 |
#endif |
| 35 |
|
| 36 |
#include "json-json.hpp" |
| 37 |
|
| 38 |
#endif /* __UJSON_H__ */ |