9 #ifndef RAD_EXCEPTIONS_HPP
10 #define RAD_EXCEPTIONS_HPP
12 #include <rad/helper.hpp>
13 #include <rad/logger.hpp>
16 #include <boost/filesystem.hpp>
36 const char*
const CFG_LOAD =
"Loading configuration file";
37 const char*
const OPT_INVALID =
"Invalid command line option";
47 explicit Exception(
const std::string& msg) : m_message(msg) {}
49 Exception(
const std::string& msg,
const std::string& info)
50 : m_message(BuildWhatArg(msg, info)) {}
57 if (&e ==
this)
return *
this;
58 std::exception::operator=(e);
59 m_message = e.m_message;
63 void AddDiagnostic(
const std::string& str) { m_message = m_message +
"\n" + str; }
65 virtual const char*
what() const noexcept {
66 return m_message.c_str();
70 std::string m_message;
73 static const std::string BuildWhatArg(
const std::string& msg,
const std::string& info) {
76 if (info.size() > 0) {
77 s <<
" (" << info <<
")";
110 #define RAD_EXCEPTION_INFO(component, proc_name, version, severity, tag, text) \
112 std::stringstream buf; \
113 buf << rad::GetTimestamp() << " " << boost::filesystem::path(__FILE__).filename().string() \
114 << " " << __LINE__ << " " << __FUNCTION__ << " " << component << " " \
115 << rad::Helper::GetHostname() << " " << proc_name << " " << std::hex \
116 << std::this_thread::get_id() << " " << getpid() << std::dec << " " << version << " " \
117 << severity << " " << tag << " " << text;
119 #define RAD_THROW(msg, component, proc_name, version, severity, tag) \
121 RAD_EXCEPTION_INFO(component, proc_name, version, severity, tag, "") \
122 throw rad::Exception(msg, buf.str());
124 #define RAD_RETHROW(exception, component, proc_name, version, severity, tag, text) \
126 RAD_EXCEPTION_INFO(component, proc_name, version, severity, tag, text) \
127 exception.AddDiagnostic(buf.str()); \
132 #endif // RAD_EXCEPTIONS_HPP
InvalidOptionException(const std::string ¶m)
Definition: exceptions.hpp:99
virtual ~RuntimeDbException() noexcept
Definition: exceptions.hpp:91
const char *const MSG_BIND_ERR
Definition: exceptions.hpp:34
void AddDiagnostic(const std::string &str)
Definition: exceptions.hpp:63
virtual const char * what() const noexcept
Definition: exceptions.hpp:65
const char *const MSG_SOCKET_ERR
Definition: exceptions.hpp:32
Definition: exceptions.hpp:97
const char *const DB_REPLY_ERR
Definition: exceptions.hpp:29
const char *const DB_API_NULL
Definition: exceptions.hpp:28
const char *const OPT_INVALID
Definition: exceptions.hpp:37
RuntimeDbException(const std::string &msg)
Definition: exceptions.hpp:88
Definition: exceptions.hpp:86
virtual ~InvalidOptionException() noexcept
Definition: exceptions.hpp:102
const char *const DB_CONTEXT_ERR
Definition: exceptions.hpp:30
RuntimeDbException(const std::string &msg, const std::string &info)
Definition: exceptions.hpp:89
Exception(const std::string &msg, const std::string &info)
Definition: exceptions.hpp:49
Exception(const Exception &e)
Definition: exceptions.hpp:52
Exception & operator=(const Exception &e)
Definition: exceptions.hpp:56
const char *const MSG_CONTEXT_ERR
Definition: exceptions.hpp:31
const char *const CFG_LOAD
Definition: exceptions.hpp:36
Definition: exceptions.hpp:45
const char *const MSG_CONNECT_ERR
Definition: exceptions.hpp:33
virtual ~Exception() noexcept
Definition: exceptions.hpp:54
Exception(const std::string &msg)
Definition: exceptions.hpp:47
const char *const MSG_CONFIG_ERR
Definition: exceptions.hpp:35