00001 #ifndef BULK_DATA_NT_EX_H
00002 #define BULK_DATA_NT_EX_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <string>
00035
00036
00037
00038
00039 #include "acserrC.h"
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #define BDNT_EX(ex, format, ...) \
00050 do { \
00051 char dummy[256]; \
00052 snprintf(dummy, 255, format, ##__VA_ARGS__); \
00053 ex = BDNTEx(std::string(dummy), std::string(__FILE__), __LINE__); \
00054 }while(0)
00055 #define BDNT_EX_THROW_EX(format, ...) \
00056 do { \
00057 char dummy[256]; \
00058 snprintf(dummy, 255, format, ##__VA_ARGS__); \
00059 throw BDNTEx(std::string(dummy), std::string(__FILE__), __LINE__); \
00060 }while(0)
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 #define BDNT_EX_CATCH_AND_LOG(call, format, ...) \
00079 do { \
00080 try \
00081 { \
00082 call; \
00083 } \
00084 catch ( BDNTEx &ex ) \
00085 { \
00086 char dummy[256]; \
00087 snprintf(dummy, 255, format, ##__VA_ARGS__); \
00088 ACS_SHORT_LOG((LM_ERROR, "%s", ex.asString().c_str())); \
00089 ACS_SHORT_LOG((LM_ERROR, "%s", dummy)); \
00090 } \
00091 catch ( ... ) \
00092 { \
00093 char dummy[256]; \
00094 snprintf(dummy, 255, format, ##__VA_ARGS__); \
00095 ACS_SHORT_LOG((LM_ERROR, "unknown exception on " #call)); \
00096 ACS_SHORT_LOG((LM_ERROR, "%s", dummy)); \
00097 } \
00098 } while(0)
00099
00103 class BDNTEx
00104 {
00105 public:
00108 BDNTEx():
00109 m_isError(false)
00110 {}
00111
00117 BDNTEx(const std::string &msg, const std::string &fileName, int lineNumber):
00118 m_errMsg(msg),
00119 m_errFileName(fileName),
00120 m_errLineNumber(lineNumber),
00121 m_isError(true)
00122 {}
00123
00133 BDNTEx(ACSErr::ErrorCode errorCode,
00134 const std::string &msg,
00135 const std::string &fileName,
00136 int lineNumber):
00137 m_errorCode(errorCode),
00138 m_errMsg(msg),
00139 m_errFileName(fileName),
00140 m_errLineNumber(lineNumber),
00141 m_isError(true)
00142 {}
00143
00146 std::string asString() const;
00147
00150 const char *asCString() const;
00151
00154 void getMessage(std::string &msg) const
00155 {
00156 msg = m_errMsg;
00157 }
00158
00161 void getFileName(std::string &fileName) const
00162 {
00163 fileName = m_errFileName;
00164 }
00165
00168 int getLineNumber() const
00169 {
00170 return m_errLineNumber;
00171 }
00172
00175 bool isError() const
00176 {
00177 return m_isError;
00178 }
00179
00180 protected:
00181 ACSErr::ErrorCode m_errorCode;
00182 std::string m_errMsg;
00183 std::string m_errFileName;
00184 int m_errLineNumber;
00185 bool m_isError;
00186 };
00187
00190 template<class T>
00191 class BDNTCompletion: public T
00192 {
00193 public:
00194
00195
00196
00197
00198
00199 BDNTCompletion():
00200 T("", -1, "")
00201 {
00202 }
00203
00204 BDNTCompletion(const char *fileName, int lineNumber, const char *funcName, const char *cause):
00205 T(fileName, lineNumber, funcName)
00206 {
00207 T::addData("Cause", cause);
00208 }
00209
00210 BDNTCompletion(const ACSErr::ErrorTrace &et, const char *fileName, int lineNumber, const char *funcName, const char *cause):
00211 T(et, fileName, lineNumber, funcName)
00212 {
00213 T::addData("Cause", cause);
00214 }
00215
00216 std::string getCause()
00217 {
00218 if ( T::isErrorFree() )
00219 {
00220 return "";
00221 }
00222
00223 return std::string(T::getErrorTraceHelper()->getData("Cause").c_str());
00224 }
00225
00226 BDNTCompletion<T> & operator=(BDNTCompletion<T> &other)
00227 {
00228 if ( this != &other )
00229 {
00230 T::operator=(other);
00231 }
00232
00233 return *this;
00234 }
00235 };
00236
00237 #endif
00238
00239