| 26 | |
| 27 | template <typename Fn, typename... Args> |
| 28 | std::invoke_result_t<Fn &&, Args &&...> ExceptionCatcher(std::string const & comment, bool & exceptionWasThrown, |
| 29 | Fn && fn, Args &&... args) noexcept |
| 30 | { |
| 31 | try |
| 32 | { |
| 33 | exceptionWasThrown = false; |
| 34 | return std::forward<Fn>(fn)(std::forward<Args>(args)...); |
| 35 | } |
| 36 | catch (RootException const & ex) |
| 37 | { |
| 38 | LOG(LWARNING, ("RootException.", comment, ex.Msg(), ex.what())); |
| 39 | } |
| 40 | catch (std::exception const & ex) |
| 41 | { |
| 42 | LOG(LWARNING, ("std::exception.", comment, ex.what())); |
| 43 | } |
| 44 | catch (...) |
| 45 | { |
| 46 | LOG(LWARNING, ("Unknown exception.", comment)); |
| 47 | } |
| 48 | |
| 49 | exceptionWasThrown = true; |
| 50 | using ReturnType = std::decay_t<std::invoke_result_t<Fn &&, Args &&...>>; |
| 51 | if constexpr (!std::is_same_v<void, ReturnType>) |
| 52 | { |
| 53 | static ReturnType const defaultResult = {}; |
| 54 | return defaultResult; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | #define DECLARE_EXCEPTION(exception_name, base_exception) \ |
| 59 | class exception_name : public base_exception \ |