Go to the documentation of this file.
22 #ifndef NRP_EXCEPTIONS_H
23 #define NRP_EXCEPTIONS_H
37 :
public std::exception
45 template<
class EXCEPTION>
46 static NRPException *nrpException(EXCEPTION &exception) noexcept
52 catch(std::exception&)
59 template<
class EXCEPTION>
62 NRPException *
const logData = NRPException::nrpException(exception);
63 if(logData ==
nullptr)
64 std::invoke(spdlogCall, exception.what());
65 else if(logData->_msgLogged !=
true)
67 std::invoke(spdlogCall, exception.what());
68 logData->_msgLogged =
true;
72 template<
class EXCEPTION = NRPExceptionNonRecoverable,
class LOG_EXCEPTION_T>
75 static_assert(std::is_nothrow_destructible_v<EXCEPTION> && std::is_constructible_v<EXCEPTION, const std::string&> ,
"Parameter EXCEPTION must be constructible from std::string&");
79 std::invoke(spdlogCall, msg);
80 if constexpr (std::is_nothrow_destructible_v<EXCEPTION> && std::is_constructible_v<EXCEPTION, const std::string&, bool>)
81 {
return EXCEPTION(msg,
true); }
83 {
return EXCEPTION(msg); }
93 template<
class EXCEPTION = NRPExceptionNonRecoverable>
96 static_assert((std::is_nothrow_destructible_v<EXCEPTION> && std::is_constructible_v<EXCEPTION, const std::string&>) || (std::is_same_v<EXCEPTION, void> && std::is_same_v<void, EXCEPTION>),
"Parameter EXCEPTION must be constructible from std::string&");
98 std::invoke(spdlogCall, msg);
99 if constexpr (std::is_nothrow_destructible_v<EXCEPTION> && std::is_constructible_v<EXCEPTION, const std::string&, bool>)
100 {
return EXCEPTION(msg,
true); }
102 {
return EXCEPTION(msg); }
107 :
_errMsg(std::forward<T>(msg)),
108 _msgLogged(msgLogged)
113 const char *
what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW override;
119 bool _msgLogged = false;
155 #endif // NRP_EXCEPTIONS_H
Base NRPException class.
Definition: nrp_exceptions.h:36
const char * what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW override
Definition: nrp_exceptions.cpp:28
void(&)(const std::string &) spdlog_out_fcn_t
Logging function type, is used by Exception.
Definition: nrp_logger.h:119
Exception for non-recoverable errors.
Definition: nrp_exceptions.h:129
NRP Logging functions.
Definition: nrp_logger.h:45
NRPException(T &&msg, bool msgLogged=false)
Definition: nrp_exceptions.h:106
static EXCEPTION logCreate(const std::string &msg, NRPLogger::spdlog_out_fcn_t spdlogCall=NRPLogger::critical)
Logs the given message to the output, then returns EXCEPTION type.
Definition: nrp_exceptions.h:94
static EXCEPTION logCreate(LOG_EXCEPTION_T &exception, const std::string &msg, NRPLogger::spdlog_out_fcn_t spdlogCall=NRPLogger::critical)
Definition: nrp_exceptions.h:73
NRPExceptionRecoverable(T &&msg, bool msgLogged=false)
Definition: nrp_exceptions.h:148
static void logOnce(EXCEPTION &exception, NRPLogger::spdlog_out_fcn_t spdlogCall=NRPLogger::critical)
Definition: nrp_exceptions.h:60
static void critical(const FormatString &fmt, const Args &...args)
NRP logging function with message formatting for critical error level.
Definition: nrp_logger.h:171
Exception for recoverable errors.
Definition: nrp_exceptions.h:143
std::string _errMsg
Definition: nrp_exceptions.h:116
NRPExceptionNonRecoverable(T &&msg, bool msgLogged=false)
Definition: nrp_exceptions.h:134