|
SWC-DB
v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
|
Go to the documentation of this file.
6 #ifndef swcdb_core_Exception_h
7 #define swcdb_core_Exception_h
18 namespace SWC {
namespace Error {
33 const char*
func =
nullptr,
34 const char*
file =
nullptr,
35 const char* inner_msg =
nullptr
51 int code() const noexcept {
56 virtual const char*
what() const noexcept
override {
61 int line() const noexcept {
66 const char*
func() const noexcept {
71 const char*
file() const noexcept {
82 void print(std::ostream& out)
const;
110 #define SWC_EXCEPTION(_code_, _msg_) \
111 ::SWC::Error::Exception(\
112 _code_, _msg_, nullptr, __LINE__, __PRETTY_FUNCTION__, __FILE__)
114 #define SWC_EXCEPTION2(_code_, _ex_, _msg_) \
115 ::SWC::Error::Exception(\
116 _code_, _msg_, &_ex_, __LINE__, __PRETTY_FUNCTION__, __FILE__)
119 #define SWC_CURRENT_EXCEPTION(_msg_) \
120 ::SWC::Error::Exception::make(std::current_exception(), _msg_)
134 #define SWC_THROW(_code_, _msg_) throw SWC_EXCEPTION(_code_, _msg_)
136 #define SWC_THROWF(_code_, _fmt_, ...) \
137 throw SWC_EXCEPTION(_code_, ::SWC::format(_fmt_, __VA_ARGS__))
139 #define SWC_THROW2F(_code_, _ex_, _fmt_, ...) \
140 throw SWC_EXCEPTION2(_code_, _ex_, ::SWC::format(_fmt_, __VA_ARGS__))
144 #define SWC_LOG_CURRENT_EXCEPTION(_s_) \
145 SWC_LOG_OUT(::SWC::LOG_ERROR, \
146 SWC_LOG_OSTREAM << SWC_CURRENT_EXCEPTION(_s_); );
150 #define SWC_TRY(_s_, _code_) \
151 try { _code_ } catch(...) { throw SWC_CURRENT_EXCEPTION(_s_); }
153 #define SWC_TRY_OR_LOG(_s_, _code_) \
154 try { _code_ } catch(...) { SWC_LOG_CURRENT_EXCEPTION(_s_); }
158 #define SWC_EXPECT(_e_, _code_) \
160 if (_code_ == ::SWC::Error::FAILED_EXPECTATION) \
161 SWC_LOG_FATAL("failed expectation: " #_e_); \
162 SWC_THROW(_code_, "failed expectation: " #_e_); \
165 #define SWC_ASSERT(_e_) SWC_EXPECT(_e_, ::SWC::Error::FAILED_EXPECTATION)
168 #define SWC_EXPECTF(_e_, _code_, _fmt_, ...) \
170 if (_code_ == ::SWC::Error::FAILED_EXPECTATION) \
171 SWC_LOG_FATALF(_fmt_, __VA_ARGS__); \
172 SWC_THROWF(_code_, _fmt_, __VA_ARGS__); \
175 #define SWC_ASSERTF(_e_, _fmt_, ...) \
176 SWC_EXPECTF(_e_, ::SWC::Error::FAILED_EXPECTATION, _fmt_, __VA_ARGS__)
181 #ifdef SWC_IMPL_SOURCE
186 #endif // swcdb_core_Exception_h
constexpr SWC_CAN_INLINE int code() const noexcept
Exception(const Exception &)=delete
void exception(int err, const std::string &msg="")
Exception & operator=(const Exception &)=delete
void print(std::ostream &out) const
The SWC-DB C++ namespace 'SWC'.
constexpr SWC_CAN_INLINE const char * file() const noexcept
static Exception make(std::exception_ptr &&eptr, std::string &&msg, Exception *prev=nullptr) noexcept
constexpr SWC_CAN_INLINE const char * func() const noexcept
friend std::ostream & operator<<(std::ostream &out, const Exception &e)
constexpr SWC_CAN_INLINE int line() const noexcept
std::string message() const
Exception & operator=(Exception &&) noexcept=delete
void print_base(std::ostream &out) const
virtual SWC_CAN_INLINE const char * what() const noexcept override
Exception(int code, std::string &&msg, Exception *prev=nullptr, int line=0, const char *func=nullptr, const char *file=nullptr, const char *inner_msg=nullptr) noexcept
SWC_CAN_INLINE const char * inner_what() const noexcept