1 #ifndef CASS_EXCEPTION__HPP
2 #define CASS_EXCEPTION__HPP
37 #include <cassandra.h>
77 size_t message_length;
78 CassError rc = cass_future_error_code(future);
79 cass_future_error_message(future, &message, &message_length);
80 string msg(message, message_length);
83 result.SetErrorCode(error_code);
110 case eFatal:
return "eFatal";
112 case eMemory:
return "eMemory";
130 return "Failed to perform query in " +
138 const string & message,
161 #define RAISE_CASS_ERROR(errc, dberr, comm) \
163 string __msg = comm; \
164 string __c = NStr::NumericToString(static_cast<int>(errc), 0, 16); \
165 __msg.append(" Cassandra error - (code: " + __c); \
166 __msg.append(string(", description: '") + \
167 cass_error_desc(errc) + "')"); \
168 NCBI_THROW(CCassandraException, dberr, __msg.c_str()); \
171 #define RAISE_CASS_FUT_ERROR(future, errc, comm) \
173 const char *__message; \
175 cass_future_error_message(future, &__message, &__msglen); \
176 CassError rc = cass_future_error_code(future); \
178 __msg.assign(__message); \
179 __msg.append(string(": ") + \
180 NStr::NumericToString(static_cast<int>(rc), 0, 16)); \
182 NCBI_THROW(CCassandraException, errc, __msg); \
184 NCBI_THROW(CCassandraException, errc, __msg + ": " + comm); \
187 #define RAISE_CASS_QRY_ERROR(future, comm) \
189 CassError rc = cass_future_error_code(future); \
190 if (rc == CASS_ERROR_SERVER_UNAVAILABLE || \
191 rc == CASS_ERROR_LIB_REQUEST_QUEUE_FULL || \
192 rc == CASS_ERROR_LIB_NO_HOSTS_AVAILABLE) \
193 RAISE_CASS_FUT_ERROR(future, eQueryFailedRestartable, comm); \
194 else if (rc == CASS_ERROR_LIB_REQUEST_TIMED_OUT || \
195 rc == CASS_ERROR_SERVER_WRITE_TIMEOUT || \
196 rc == CASS_ERROR_SERVER_READ_TIMEOUT) \
197 RAISE_CASS_FUT_ERROR(future, eQueryTimeout, comm); \
199 RAISE_CASS_FUT_ERROR(future, eQueryFailed, comm); \
202 #define RAISE_CASS_CONN_ERROR(future, comm) \
203 RAISE_CASS_FUT_ERROR(future, eFailedToConn, comm)
205 #define RAISE_DB_ERROR(errc, comm) \
207 string ___msg = comm; \
208 NCBI_THROW(CCassandraException, errc, comm); \
211 #define RAISE_DB_QRY_TIMEOUT(tspent, tmargin, msg) \
213 string ___msg = msg; \
214 if ((tmargin) != 0) \
215 ___msg.append(string(", timeout ") + \
216 NStr::NumericToString(tmargin) + \
217 "ms (spent: " + NStr::NumericToString(tspent) + \
219 NCBI_EXCEPTION_VAR(db_exception, CCassandraException, eQueryTimeout, ___msg); \
220 db_exception.SetOpTime( (tspent) ); \
221 NCBI_EXCEPTION_THROW(db_exception); \
#define BEGIN_IDBLOB_SCOPE
void SetOpTime(int64_t optimeMS)
NCBI_EXCEPTION_DEFAULT(CCassandraException, CException)
@ eQueryFailedRestartable
void x_Assign(const CException &src) override
Helper method for copying exception data.
const char * GetErrCodeString(void) const override
Get error code interpreted as text.
int64_t GetOpTime(void) const
string TimeoutMsg(void) const
void x_Init(const CDiagCompileInfo &info, const string &message, const CException *prev_exception, EDiagSev severity) override
Helper method for initializing exception data.
void SetErrorCode(EErrCode error_code)
static CCassandraException s_ProduceException(CassFuture *future, CCassandraException::EErrCode error_code)
Incapsulate compile time information such as __FILE__, __LINE__, NCBI_MODULE, current function.
The NCBI C++ standard methods for dealing with std::string.
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
EDiagSev
Severity level for the posted diagnostics.
TErrCode GetErrCode(void) const
Get error code.
virtual void x_Init(const CDiagCompileInfo &info, const string &message, const CException *prev_exception, EDiagSev severity)
Helper method for initializing exception data.
virtual void x_InitErrCode(CException::EErrCode err_code)
Helper method for initializing error code.
virtual void x_Assign(const CException &src)
Helper method for copying exception data.
EErrCode
Error types that an application can generate.
#define NCBI_EXCEPTION(exception_class, err_code, message)
Generic macro to make an exception, given the exception class, error code and message string.
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
void Info(CExceptionArgs_Base &args)
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Defines NCBI C++ exception handling.
NCBI C++ stream class wrappers for triggering between "new" and "old" C++ stream libraries.