diff --git a/base/exception.hpp b/base/exception.hpp index f062a0564d..8e189fea42 100644 --- a/base/exception.hpp +++ b/base/exception.hpp @@ -1,6 +1,7 @@ #pragma once #include "base/internal/message.hpp" +#include "base/logging.hpp" #include "base/macros.hpp" #include @@ -23,6 +24,29 @@ private: std::string m_msg; }; +template +std::result_of_t ExceptionCatcher(std::string const & comment, Fn && fn, + Args &&... args) noexcept +{ + try + { + return std::forward(fn)(std::forward(args)...); + } + catch (RootException const & ex) + { + LOG(LWARNING, ("RootException.", comment, ex.Msg(), ex.what())); + } + catch (std::exception const & ex) + { + LOG(LWARNING, ("std::exception.", comment, ex.what())); + } + catch (...) + { + LOG(LWARNING, ("Unknown exception.", comment)); + } + return {}; +} + #define DECLARE_EXCEPTION(exception_name, base_exception) \ class exception_name : public base_exception \ { \