-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathException.cpp
203 lines (168 loc) · 6.07 KB
/
Exception.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include "BaseLib/Exception.h"
#include "BaseLib/Thread.h"
#include "BaseLib/Utility.h"
namespace BaseLib {
std::ostream& operator<<(std::ostream& str, const ExceptionBase::ExceptionType& type) throw()
{
#define PRINTOUT(name) case name: str << #name; break;
switch(type)
{
PRINTOUT(ExceptionBase::ExceptionType::GeneralException)
PRINTOUT(ExceptionBase::ExceptionType::Exception)
PRINTOUT(ExceptionBase::ExceptionType::IOException)
PRINTOUT(ExceptionBase::ExceptionType::ErrorException)
PRINTOUT(ExceptionBase::ExceptionType::WarningException)
PRINTOUT(ExceptionBase::ExceptionType::CriticalException)
PRINTOUT(ExceptionBase::ExceptionType::FatalException)
PRINTOUT(ExceptionBase::ExceptionType::DeadlockException)
PRINTOUT(ExceptionBase::ExceptionType::InterruptedException)
PRINTOUT(ExceptionBase::ExceptionType::UnsupportedException)
default:
IDEBUG() << " did not recognize ExceptionType";
break;
}
#undef PRINTOUT
return str;
}
/*-----------------------------------------------------------------------
constructor/destructor/functions ExceptionTracer
------------------------------------------------------------------------- */
ExceptionTracer::ExceptionTracer()
try
{
#ifdef USE_GCC
void* array[25];
int nSize = backtrace(array, 25);
char** symbols = backtrace_symbols(array, nSize);
std::stringstream stream;
stream << PRETTY_FUNCTION << std::endl;
for(int i = 0; i < nSize; i++)
{
if(symbols[i] == NULL) continue;
stream << symbols[i] << std::endl;
}
exceptionTrace_ = stream.str();
free(symbols);
#endif
}
catch(std::exception ex)
{
IDEBUG() << "ExceptionTracer failed: " << ex.what();
}
catch(...)
{
IDEBUG() << "ExceptionTracer failed: Unknown error.";
}
ExceptionTracer::~ExceptionTracer()
{
}
std::string ExceptionTracer::GetExceptionTrace() const throw()
{
return exceptionTrace_;
}
/*-----------------------------------------------------------------------
constructor/destructor/functions ExceptionBase
------------------------------------------------------------------------- */
ExceptionBase::ExceptionBase(ExceptionBase::ExceptionType type)
//: ObjectBase()
: exceptionType_(type)
{
//static int count = 0;
//stringstream ostr;
//ostr << "BaseLib.Exception." << type << "." << count++;
//ObjectBase::SetObjectName(ostr.str());
}
ExceptionBase::~ExceptionBase() throw()
{
}
ExceptionBase::ExceptionType ExceptionBase::GetExceptionType() const throw()
{
return exceptionType_;
}
/*-----------------------------------------------------------------------
constructor/destructor/functions Exception
------------------------------------------------------------------------- */
GeneralException::GeneralException(std::string txt, ExceptionBase::ExceptionType type)
: std::runtime_error(txt)
, ExceptionBase(type)
{
Thread* thread = Thread::currentThread();
std::stringstream ostr;
ostr << "---------------------------------- Intact Exception ----------------------------------" << std::endl;
ostr << "Type: \t" << this->GetExceptionType() << " in thread " << Thread::currentThreadId() << std::endl;
if(thread)
{
ostr << "Thread details \t" << thread->getThreadDetails() << std::endl;
}
ostr << "Local timestamp: \t" << Utility::PrintCurrentTimeMsec() << std::endl;
ostr << "Stack trace: \t" << std::endl << GetExceptionTrace() << std::endl;
ostr << "Message details: \t" << std::runtime_error::what() << std::endl;
ostr << "--------------------------------------------------------------------------------------" << std::endl;
exceptionMsg_ = ostr.str();
}
GeneralException::~GeneralException() throw()
{
}
std::string GeneralException::msg() const throw()
{
return exceptionMsg_;
}
const char* GeneralException::what() const throw()
{
return exceptionMsg_.c_str();
}
/*-----------------------------------------------------------------------
specialized exception classes
------------------------------------------------------------------------- */
Exception::Exception(std::string txt, ExceptionBase::ExceptionType type)
: GeneralException(txt, type)
{
// NOTE: This exception is used in allowed states of the system
//DebugReport::GetOrCreate()->ReportException(exceptionMsg_);
}
IOException::IOException(std::string txt, ExceptionBase::ExceptionType type)
: GeneralException(txt, type)
{
DebugReport::GetOrCreate()->ReportException(exceptionMsg_);
}
ErrorException::ErrorException(std::string txt, ExceptionBase::ExceptionType type)
: GeneralException(txt, type)
{
DebugReport::GetOrCreate()->ReportException(exceptionMsg_);
}
WarningException::WarningException(std::string txt, ExceptionBase::ExceptionType type)
: GeneralException(txt, type)
{
DebugReport::GetOrCreate()->ReportException(exceptionMsg_);
}
CriticalException::CriticalException(std::string txt, ExceptionBase::ExceptionType type)
: GeneralException(txt, type)
{
DebugReport::GetOrCreate()->ReportException(exceptionMsg_);
}
FatalException::FatalException(std::string txt, ExceptionBase::ExceptionType type)
: GeneralException(txt, type)
{
DebugReport::GetOrCreate()->ReportException(exceptionMsg_);
}
DeadlockException::DeadlockException(std::string txt, ExceptionBase::ExceptionType type)
: GeneralException(txt, type)
{
DebugReport::GetOrCreate()->ReportException(exceptionMsg_);
}
CancelException::CancelException(std::string txt, ExceptionBase::ExceptionType type)
: GeneralException(txt, type)
{
DebugReport::GetOrCreate()->ReportException(exceptionMsg_);
}
InterruptedException::InterruptedException(std::string txt, ExceptionBase::ExceptionType type)
: GeneralException(txt, type)
{
DebugReport::GetOrCreate()->ReportException(exceptionMsg_);
}
UnsupportedException::UnsupportedException(std::string txt, ExceptionBase::ExceptionType type)
: GeneralException(txt, type)
{
DebugReport::GetOrCreate()->ReportException(exceptionMsg_);
}
}