diff --git a/include/rfl/toml/read.hpp b/include/rfl/toml/read.hpp index b9a26cb3..ae7c2168 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 (const std::exception& 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.