Since using c++20 and coroutines, I'm running more and more into issues because you cannot await a coroutine in a catch-clause. For my code I've now created a wrapper to deal with this, it catches the exception and returns an expected which will have an error on failure:
template <typename Type, unsigned Rapidjson_Parseflags = rapidjson::kParseDefaultFlags>
std::expected<Type, std::string> try_from_json(std::string_view json) noexcept
{
try
{
return json_dto::from_json<Type, Rapidjson_Parseflags>(json_dto::make_string_ref(json.data(), json.size()));
}
catch (const json_dto::ex_t& e)
{
return tl::make_unexpected(std::string{ e.what() });
}
}
plus a whole lot of other overloads, of course. It'd be nice to have support for something like this directly inside json_dto. I realize that std::expected is only introduced in c++23 (which would require bumping the c++ version), but we could potentially only do this if compiling with a recent enough c++-version, use a third-party library (something like tl::expected), or implement our own (like we do with json_dto::Optional)
Any ideas on this? I wouldn't mind doing the work if it's something you'd be interested in merging.
Since using c++20 and coroutines, I'm running more and more into issues because you cannot await a coroutine in a catch-clause. For my code I've now created a wrapper to deal with this, it catches the exception and returns an expected which will have an error on failure:
plus a whole lot of other overloads, of course. It'd be nice to have support for something like this directly inside json_dto. I realize that
std::expectedis only introduced in c++23 (which would require bumping the c++ version), but we could potentially only do this if compiling with a recent enough c++-version, use a third-party library (something liketl::expected), or implement our own (like we do withjson_dto::Optional)Any ideas on this? I wouldn't mind doing the work if it's something you'd be interested in merging.