MCPcopy Create free account
hub / github.com/comaps/comaps / ExceptionCatcher

Function ExceptionCatcher

libs/base/exception.hpp:28–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26
27template <typename Fn, typename... Args>
28std::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 \

Callers 2

UNIT_TESTFunction · 0.85

Calls 1

whatMethod · 0.45

Tested by 1

UNIT_TESTFunction · 0.68