NCBI C++ ToolKit
cass_exception.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef CASS_EXCEPTION__HPP
2 #define CASS_EXCEPTION__HPP
3 
4 /* $Id: cass_exception.hpp 102021 2024-03-19 15:07:02Z saprykin $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Dmitri Dmitrienko
30  *
31  * File Description:
32  *
33  * Exceptions used in the cassandra driver
34  *
35  */
36 
37 #include <cassandra.h>
38 #include <corelib/ncbistre.hpp>
39 #include <corelib/ncbistr.hpp>
40 #include <corelib/ncbiexpt.hpp>
41 
42 #include "IdCassScope.hpp"
43 
46 
48  : public CException
49 {
50 public:
51  enum EErrCode {
52  eUnknown = 2000,
66 
67  // Came from class EError (IdLogUtl.hpp)
73  };
74 
75  NCBI_STD_DEPRECATED("Deprecated and will be deleted after 06/01/2024")
77  {
78  const char *message;
79  size_t message_length;
80  CassError rc = cass_future_error_code(future);
81  cass_future_error_message(future, &message, &message_length);
82  string msg(message, message_length);
83  msg.append(": ").append(NStr::NumericToString(static_cast<int>(rc), 0, 16));
85  result.SetErrorCode(error_code);
86  return result;
87  }
88 
89  void SetErrorCode(EErrCode error_code)
90  {
91  x_InitErrCode(static_cast<CException::EErrCode>(error_code));
92  }
93 
94  const char* GetErrCodeString(void) const override
95  {
96  switch (GetErrCode()) {
97  case eUnknown: return "eUnknown";
98  case eRsrcFailed: return "eRsrcFailed";
99  case eFailedToConn: return "eFailedToConn";
100  case eConnTimeout: return "eConnTimeout";
101  case eQueryFailedRestartable: return "eQueryFailedRestartable";
102  case eQueryFailed: return "eQueryFailed";
103  case eBindFailed: return "eBindFailed";
104  case eQueryTimeout: return "eQueryTimeout";
105  case eFetchFailed: return "eFetchFailed";
106  case eExtraFetch: return "eExtraFetch";
107  case eConvFailed: return "eConvFailed";
108  case eMissData: return "eMissData";
109  case eInconsistentData: return "eInconsistentData";
110  case eNotFound: return "eNotFound";
111  case eSeqFailed: return "eSeqFailed";
112  case eFatal: return "eFatal";
113  case eGeneric: return "eGeneric";
114  case eMemory: return "eMemory";
115  case eUserCancelled: return "eUserCancelled";
116  default: return CException::GetErrCodeString();
117  }
118  }
119 
120  NCBI_STD_DEPRECATED("Deprecated and will be deleted after 06/01/2024. Use CException::GetMsg()")
121  void SetOpTime(int64_t optimeMS)
122  {
123  m_OpTimeMs = optimeMS;
124  }
125 
126  NCBI_STD_DEPRECATED("Deprecated and will be deleted after 06/01/2024. Use CException::GetMsg()")
128  {
129  return m_OpTimeMs;
130  }
131 
132  NCBI_STD_DEPRECATED("Deprecated and will be deleted after 06/01/2024. Use CException::GetMsg()")
134  {
135  return "Failed to perform query in " + to_string(m_OpTimeMs) + "ms, timed out";
136  }
137 
139 
140 protected:
142  const string & message,
143  const CException * prev_exception,
144  EDiagSev severity) override
145  {
146  m_OpTimeMs = 0;
147  ERR_POST(Info << "CCassandraException: " << message);
148  CException::x_Init(info, message, prev_exception, severity);
149  }
150 
151  void x_Assign(const CException & src) override
152  {
153  const CCassandraException* src_ex = dynamic_cast<const CCassandraException*>(&src);
154  if (src_ex) {
155  m_OpTimeMs = src_ex->m_OpTimeMs;
156  }
158  }
159 
161 };
162 
163 #define RAISE_CASS_ERROR(errc, dberr, comm) \
164  do { \
165  string macro_msg = comm; \
166  string macro_c = NStr::NumericToString(static_cast<int>(errc), 0, 16); \
167  macro_msg.append(" Cassandra error - (code: " + macro_c); \
168  macro_msg.append(string(", description: '") + \
169  cass_error_desc(errc) + "')"); \
170  NCBI_THROW(CCassandraException, dberr, macro_msg.c_str()); \
171  } while (0)
172 
173 #define RAISE_DB_ERROR(errc, comm) \
174  NCBI_THROW(CCassandraException, errc, comm); \
175 
177 
178 #endif // CASS_EXCEPTION__HPP
#define static
#define END_IDBLOB_SCOPE
Definition: IdCassScope.hpp:40
#define BEGIN_IDBLOB_SCOPE
Definition: IdCassScope.hpp:39
USING_NCBI_SCOPE
int64_t GetOpTime() const
void SetOpTime(int64_t optimeMS)
NCBI_EXCEPTION_DEFAULT(CCassandraException, CException)
string TimeoutMsg() const
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.
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.
Definition: ncbidiag.hpp:65
The NCBI C++ standard methods for dealing with std::string.
Int8 int64_t
string
Definition: cgiapp.hpp:687
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
EDiagSev
Severity level for the posted diagnostics.
Definition: ncbidiag.hpp:650
TErrCode GetErrCode(void) const
Get error code.
Definition: ncbiexpt.cpp:453
virtual void x_Init(const CDiagCompileInfo &info, const string &message, const CException *prev_exception, EDiagSev severity)
Helper method for initializing exception data.
Definition: ncbiexpt.cpp:509
virtual void x_InitErrCode(CException::EErrCode err_code)
Helper method for initializing error code.
Definition: ncbiexpt.cpp:567
virtual void x_Assign(const CException &src)
Helper method for copying exception data.
Definition: ncbiexpt.cpp:536
EErrCode
Error types that an application can generate.
Definition: ncbiexpt.hpp:884
#define NCBI_EXCEPTION(exception_class, err_code, message)
Generic macro to make an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:695
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
Definition: ncbiexpt.cpp:444
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
#define NCBI_STD_DEPRECATED(message)
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.
Definition: ncbistr.hpp:673
static MDB_envinfo info
Definition: mdb_load.c:37
Defines NCBI C++ exception handling.
NCBI C++ stream class wrappers for triggering between "new" and "old" C++ stream libraries.
else result
Definition: token2.c:20
Modified on Wed May 15 15:06:51 2024 by modify_doxy.py rev. 669887