From c5114a57c5460916141260b5d31680f82fdda324 Mon Sep 17 00:00:00 2001 From: Josh Lehan Date: Thu, 3 Mar 2022 18:25:55 -0800 Subject: Updated text to elaborate on JSON exceptions Mentioning operator<< and operator>> as throwing Noting preferred usage of parse() and dump() Signed-off-by: Josh Lehan Change-Id: I1ffdc4b39e518ec348a553eac5080accf75fae8e --- COMMON_ERRORS.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'COMMON_ERRORS.md') diff --git a/COMMON_ERRORS.md b/COMMON_ERRORS.md index 7e6d26cbf6..6bb5c05155 100644 --- a/COMMON_ERRORS.md +++ b/COMMON_ERRORS.md @@ -72,6 +72,8 @@ Commonly used methods that fall into this pattern: - nlohmann::json::get - nlohmann::json::get\_ref - nlohmann::json::get\_to +- nlohmann::json::operator\<\< +- nlohmann::json::operator\>\> - std::filesystem::create\_directory - std::filesystem::rename - std::filesystem::file\_size @@ -79,12 +81,18 @@ Commonly used methods that fall into this pattern: - std::stol - std::stoll -#### special/strange case: +#### Special note: JSON -nlohmann::json::parse by default throws on failure, but also accepts a optional -argument that causes it to not throw. Please consult the other examples in the -code for how to handle errors. +`nlohmann::json::parse` by default +[throws](https://json.nlohmann.me/api/basic_json/parse/) on failure, but +also accepts an optional argument that causes it to not throw: set the 3rd +argument to `false`. +`nlohmann::json::dump` by default +[throws](https://json.nlohmann.me/api/basic_json/dump/) on failure, but also +accepts an optional argument that causes it to not throw: set the 4th +argument to `replace`. Although `ignore` preserves content 1:1, `replace` +is preferred from a security point of view. #### Special note: Boost there is a whole class of boost asio functions that provide both a method that -- cgit v1.2.3