From 292dd8919ed0c976a2ee6143768fc3a527f253b4 Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Fri, 6 Jan 2023 00:31:05 +0100 Subject: [PATCH] Add `try`/`catch` around json parser As got: ``` terminate called after throwing an instance of 'nlohmann::detail::parse_error' terminate called recursively what(): [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal terminate called recursively ``` --- main.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 28eacbf..0c6f021 100644 --- a/main.cpp +++ b/main.cpp @@ -310,7 +310,16 @@ json getJson(unsigned short threadId, string url, string directoryPath) string finalUrl = "https://www.googleapis.com/youtube/v3/" + url + "&key=" + API_KEY; #endif string content = getHttps(finalUrl); - json data = json::parse(content); + json data; + try + { + data = json::parse(content); + } + catch (json::parse_error& ex) + { + PRINT(threadId, "Parse error for " << finalUrl << ", as got: " << content) + exit(1); + } ostringstream toString; toString << CHANNELS_DIRECTORY << directoryPath << "/" << requestsPerChannel << ".json";