Added walkExceptionCause helper function.

This commit is contained in:
Patrick 2024-12-16 20:53:17 +01:00
parent aa804a2a99
commit 48aeb32ee5

View File

@ -48,5 +48,30 @@ inline decltype(auto) ensure(TCondition&& condition, TExceptionArgs&&... args)
}
return std::forward<TCondition>(condition);
}
template<typename TFunc>
void walkExceptionCause(const std::exception_ptr& cause, TFunc func)
{
if (cause)
{
try
{
std::rethrow_exception(cause);
}
catch(Exception& exc)
{
func(exc);
walkExceptionCause(exc.getCause(), std::move(func));
}
catch(std::exception& exc)
{
func(exc);
}
catch(...)
{
func(nullptr);
}
}
}
} // namespace mijin
#endif // MIJIN_UTIL_EXCEPTION_HPP_INCLUDED