-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStructuredException.cpp
More file actions
103 lines (88 loc) · 2.7 KB
/
StructuredException.cpp
File metadata and controls
103 lines (88 loc) · 2.7 KB
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
#include <iostream>
#include <sstream>
#include "StructuredException.hpp"
dump::StructuredException::StructuredException(unsigned int nSeCode, _EXCEPTION_POINTERS* pExcPointers)
: m_nSeCode(nSeCode), m_pExcPointers(pExcPointers)
{}
dump::StructuredException::StructuredException(StructuredException& a_rhs)
: m_nSeCode(a_rhs.m_nSeCode), m_pExcPointers(a_rhs.m_pExcPointers)
{}
unsigned int
dump::StructuredException::GetSeCode() const
{
return m_nSeCode;
}
_EXCEPTION_POINTERS*
dump::StructuredException::GetSePointers() const
{
return m_pExcPointers;
}
void*
dump::StructuredException::GetExceptionAddress() const
{
return m_pExcPointers->ExceptionRecord->ExceptionAddress;
}
void
dump::StructuredException::Delete()
{
delete this;
}
int
dump::StructuredException::ReportError(unsigned int a_type, unsigned int a_IDHelp) const
{
/* TODO
CString strMessage;
GetErrorMessage(strMessage);
*/
std::cerr << __func__ << ": " //<< strMessage
<< ", type=" << a_type << ", IDHelp=" << a_IDHelp << '\n';
return 0; // return rc;
}
namespace {
void
SetErrorDescription(std::string& a_description, unsigned int a_SECode, _EXCEPTION_POINTERS* a_excPointers)
{
std::ostringstream oss;
oss << "Exception " << a_SECode << " at address 0x" << a_excPointers;
a_description.assign(oss.str());
}
} // namespace
#define CASE(nSeCode, a_description) \
case EXCEPTION_##nSeCode: \
SetErrorDescription( \
a_description, EXCEPTION_##nSeCode, (_EXCEPTION_POINTERS*)m_pExcPointers->ExceptionRecord->ExceptionAddress); \
break;
bool
dump::StructuredException::GetErrorMessage(std::string& a_description) const
{
bool succeeded = true;
switch (m_nSeCode) {
CASE(ACCESS_VIOLATION, a_description);
CASE(DATATYPE_MISALIGNMENT, a_description);
CASE(BREAKPOINT, a_description);
CASE(SINGLE_STEP, a_description);
CASE(ARRAY_BOUNDS_EXCEEDED, a_description);
CASE(FLT_DENORMAL_OPERAND, a_description);
CASE(FLT_DIVIDE_BY_ZERO, a_description);
CASE(FLT_INEXACT_RESULT, a_description);
CASE(FLT_INVALID_OPERATION, a_description);
CASE(FLT_OVERFLOW, a_description);
CASE(FLT_STACK_CHECK, a_description);
CASE(FLT_UNDERFLOW, a_description);
CASE(INT_DIVIDE_BY_ZERO, a_description);
CASE(INT_OVERFLOW, a_description);
CASE(PRIV_INSTRUCTION, a_description);
CASE(IN_PAGE_ERROR, a_description);
CASE(ILLEGAL_INSTRUCTION, a_description);
CASE(NONCONTINUABLE_EXCEPTION, a_description);
CASE(STACK_OVERFLOW, a_description);
CASE(INVALID_DISPOSITION, a_description);
CASE(GUARD_PAGE, a_description);
CASE(INVALID_HANDLE, a_description);
default:
a_description.assign("Unknown exception");
succeeded = false;
break;
}
return succeeded;
}