diff --git a/source/mijin/util/exception.hpp b/source/mijin/util/exception.hpp index 2074f84..7ad87e3 100644 --- a/source/mijin/util/exception.hpp +++ b/source/mijin/util/exception.hpp @@ -48,5 +48,30 @@ inline decltype(auto) ensure(TCondition&& condition, TExceptionArgs&&... args) } return std::forward(condition); } + +template +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