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

Go to the SVN repository for this file.

1 #ifndef SRA__READER__SRA__EXCEPTION__HPP
2 #define SRA__READER__SRA__EXCEPTION__HPP
3 /* $Id: exception.hpp 100806 2023-09-14 14:12:34Z vasilche $
4  * ===========================================================================
5  *
6  * PUBLIC DOMAIN NOTICE
7  * National Center for Biotechnology Information
8  *
9  * This software/database is a "United States Government Work" under the
10  * terms of the United States Copyright Act. It was written as part of
11  * the author's official duties as a United States Government employee and
12  * thus cannot be copyrighted. This software/database is freely available
13  * to the public for use. The National Library of Medicine and the U.S.
14  * Government have not placed any restriction on its use or reproduction.
15  *
16  * Although all reasonable efforts have been taken to ensure the accuracy
17  * and reliability of the software and data, the NLM and the U.S.
18  * Government do not and cannot warrant the performance or results that
19  * may be obtained by using this software or data. The NLM and the U.S.
20  * Government disclaim all warranties, express or implied, including
21  * warranties of performance, merchantability or fitness for any particular
22  * purpose.
23  *
24  * Please cite the author in any work or product based on this material.
25  *
26  * ===========================================================================
27  *
28  * Authors: Eugene Vasilchenko
29  *
30  * File Description:
31  * SRA SDK exceptions
32  *
33  */
34 
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/ncbiexpt.hpp>
37 
38 
39 typedef uint32_t rc_t; // from <klib/rc.h>
40 
41 
44 
45 class CSeq_entry;
46 
47 /////////////////////////////////////////////////////////////////////////////
48 // CSraException
49 /////////////////////////////////////////////////////////////////////////////
50 
51 #ifndef NCBI_EXCEPTION3_VAR
52 /// Create an instance of the exception with one additional parameter.
53 # define NCBI_EXCEPTION3_VAR(name, exc_cls, err_code, msg, extra1, extra2) \
54  exc_cls name(DIAG_COMPILE_INFO, 0, exc_cls::err_code, msg, \
55  extra1, extra2)
56 #endif
57 
58 #ifndef NCBI_EXCEPTION3
59 # define NCBI_EXCEPTION3(exc_cls, err_code, msg, extra1, extra2) \
60  NCBI_EXCEPTION3_VAR(NCBI_EXCEPTION_EMPTY_NAME, \
61  exc_cls, err_code, msg, extra1, extra2)
62 #endif
63 
64 #ifndef NCBI_THROW3
65 # define NCBI_THROW3(exc_cls, err_code, msg, extra1, extra2) \
66  throw NCBI_EXCEPTION3(exc_cls, err_code, msg, extra1, extra2)
67 #endif
68 
69 #ifndef NCBI_RETHROW3
70 # define NCBI_RETHROW3(prev_exc, exc_cls, err_code, msg, extra1, extra2) \
71  throw exc_cls(DIAG_COMPILE_INFO, &(prev_exc), exc_cls::err_code, msg, \
72  extra1, extra2)
73 #endif
74 
75 
78 {
79 public:
80  /// Error types that corelib can generate.
81  ///
82  /// These generic error conditions can occur for corelib applications.
83  enum EErrCode {
85  eNullPtr, ///< Null pointer error
86  eAddRefFailed, ///< AddRef failed
87  eInvalidArg, ///< Invalid argument error
88  eInitFailed, ///< Initialization failed
89  eNotFound, ///< Data not found
90  eInvalidState, ///< State of object is invalid for the operation
91  eInvalidIndex, ///< Invalid index for array-like retrieval
92  eNotFoundDb, ///< DB main file not found
93  eNotFoundTable, ///< DB table not found
94  eNotFoundColumn,///< DB column not found
95  eNotFoundValue, ///< DB value not found
96  eDataError, ///< VDB data is incorrect
97  eNotFoundIndex, ///< VDB index not found
98  eProtectedDb, ///< DB is protected
99  eTimeout, ///< timeout, re-try logic is recommended
100  eUnknownError ///< Not used
101  };
102  /// Constructors.
104  const CException* prev_exception,
105  EErrCode err_code,
106  const string& message,
107  EDiagSev severity = eDiag_Error);
109  const CException* prev_exception,
110  EErrCode err_code,
111  const string& message,
112  rc_t rc,
113  EDiagSev severity = eDiag_Error);
115  const CException* prev_exception,
116  EErrCode err_code,
117  const string& message,
118  rc_t rc,
119  const string& param,
120  EDiagSev severity = eDiag_Error);
122  const CException* prev_exception,
123  EErrCode err_code,
124  const string& message,
125  rc_t rc,
126  int64_t param,
127  EDiagSev severity = eDiag_Error);
128  CSraException(const CSraException& other);
129 
130  ~CSraException(void) noexcept;
131 
132  /// Report "non-standard" attributes.
133  virtual void ReportExtra(ostream& out) const;
134 
135  virtual const char* GetType(void) const;
136 
137  /// Translate from the error code value to its string representation.
138  typedef int TErrCode;
139  virtual TErrCode GetErrCode(void) const;
140 
141  /// Translate from the error code value to its string representation.
142  virtual const char* GetErrCodeString(void) const;
143 
144  rc_t GetRC(void) const
145  {
146  return m_RC;
147  }
148 
149  const string& GetParam(void) const
150  {
151  return m_Param;
152  }
153  void SetParam(const string& param)
154  {
155  m_Param = param;
156  }
157 
158  static bool IsTimeout(rc_t rc);
159 
160  static void ReportError(const char* msg, rc_t rc);
161 
162 protected:
163  /// Constructor.
164  CSraException(void);
165 
166  /// Helper clone method.
167  virtual const CException* x_Clone(void) const;
168 
169 private:
171  string m_Param;
172 };
173 
174 
175 #ifndef NCBI_THROW2_FMT
176 # define NCBI_THROW2_FMT(exception_class, err_code, message, extra) \
177  throw NCBI_EXCEPTION2(exception_class, err_code, FORMAT(message), extra)
178 #endif
179 
180 
181 #define CHECK_VDB_TIMEOUT(msg, rc) \
182  do { \
183  if ( rc && CSraException::IsTimeout(rc) ) \
184  NCBI_THROW2(CSraException, eTimeout, msg, rc); \
185  } while (0)
186 #define CHECK_VDB_TIMEOUT_FMT(msg, rc) \
187  do { \
188  if ( rc && CSraException::IsTimeout(rc) ) \
189  NCBI_THROW2_FMT(CSraException, eTimeout, msg, rc); \
190  } while (0)
191 
192 
195 
196 #endif // SRA__READER__SRA__EXCEPTION__HPP
uint32_t rc_t
Incapsulate compile time information such as __FILE__, __LINE__, NCBI_MODULE, current function.
Definition: ncbidiag.hpp:65
Definition: Seq_entry.hpp:56
EErrCode
Error types that corelib can generate.
Definition: exception.hpp:83
@ eNotFoundValue
DB value not found.
Definition: exception.hpp:95
@ eProtectedDb
DB is protected.
Definition: exception.hpp:98
@ eDataError
VDB data is incorrect.
Definition: exception.hpp:96
@ eAddRefFailed
AddRef failed.
Definition: exception.hpp:86
@ eNotFoundColumn
DB column not found.
Definition: exception.hpp:94
@ eInvalidArg
Invalid argument error.
Definition: exception.hpp:87
@ eNullPtr
Null pointer error.
Definition: exception.hpp:85
@ eNotFoundDb
DB main file not found.
Definition: exception.hpp:92
@ eTimeout
timeout, re-try logic is recommended
Definition: exception.hpp:99
@ eNotFound
Data not found.
Definition: exception.hpp:89
@ eInitFailed
Initialization failed.
Definition: exception.hpp:88
@ eNotFoundTable
DB table not found.
Definition: exception.hpp:93
@ eNotFoundIndex
VDB index not found.
Definition: exception.hpp:97
@ eInvalidState
State of object is invalid for the operation.
Definition: exception.hpp:90
@ eInvalidIndex
Invalid index for array-like retrieval.
Definition: exception.hpp:91
void SetParam(const string &param)
Definition: exception.hpp:153
int TErrCode
Translate from the error code value to its string representation.
Definition: exception.hpp:138
const string & GetParam(void) const
Definition: exception.hpp:149
rc_t GetRC(void) const
Definition: exception.hpp:144
string m_Param
Definition: exception.hpp:171
Include a standard set of the NCBI C++ Toolkit most basic headers.
std::ofstream out("events_result.xml")
main entry point for tests
Int8 int64_t
Uint4 uint32_t
EDiagSev
Severity level for the posted diagnostics.
Definition: ncbidiag.hpp:650
@ eDiag_Error
Error message.
Definition: ncbidiag.hpp:653
virtual void ReportExtra(ostream &out) const
Report "non-standard" attributes.
Definition: ncbiexpt.cpp:428
virtual const char * GetType(void) const
Get class name as a string.
Definition: ncbiexpt.cpp:268
TErrCode GetErrCode(void) const
Get error code.
Definition: ncbiexpt.cpp:453
virtual const CException * x_Clone(void) const
Helper method for cloning the exception.
Definition: ncbiexpt.cpp:503
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
Definition: ncbiexpt.cpp:444
#define EXCEPTION_VIRTUAL_BASE
Do not use virtual base classes in exception declaration at all, because in this case derived class s...
Definition: ncbiexpt.hpp:1388
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define NCBI_SRAREAD_EXPORT
Definition: ncbi_export.h:1227
static MDB_envinfo info
Definition: mdb_load.c:37
Defines NCBI C++ exception handling.
uint32_t rc_t
Definition: exception.hpp:39
Modified on Wed Apr 24 14:16:48 2024 by modify_doxy.py rev. 669887