From 3ecad0d3c39d139f586207e55c7b126acc527f32 Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Mon, 9 Jun 2025 18:29:14 +0200 Subject: [PATCH 1/2] Added support for exception-free TOML --- include/rfl/toml/read.hpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/include/rfl/toml/read.hpp b/include/rfl/toml/read.hpp index b9a26cb3..c9a722b7 100644 --- a/include/rfl/toml/read.hpp +++ b/include/rfl/toml/read.hpp @@ -29,9 +29,21 @@ auto read(InputVarType _var) { /// Reads a TOML string. template Result> read( - const std::string_view _toml_str) { - auto table = ::toml::parse(_toml_str); - return read(&table); + const std::string_view _toml_str) noexcept { +#if TOML_EXCEPTIONS + try { + auto table = ::toml::parse(_toml_str); + return read(&table); + } catch (std::runtime_error& e) { + return error(e.what()); + } +#else + auto result = ::toml::parse(_toml_str); + if (!result) { + return error(std::string(result.error().description())); + } + return read(&result.table()); +#endif } /// Parses an object from a stringstream. From 52f98819b68300f5e48d4281a574c3334dcf55fa Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Mon, 9 Jun 2025 18:37:01 +0200 Subject: [PATCH 2/2] Catch std::exception instead of std::runtime_error --- include/rfl/toml/read.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rfl/toml/read.hpp b/include/rfl/toml/read.hpp index c9a722b7..ae7c2168 100644 --- a/include/rfl/toml/read.hpp +++ b/include/rfl/toml/read.hpp @@ -34,7 +34,7 @@ Result> read( try { auto table = ::toml::parse(_toml_str); return read(&table); - } catch (std::runtime_error& e) { + } catch (const std::exception& e) { return error(e.what()); } #else