-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNouException.cpp
More file actions
109 lines (90 loc) · 2.21 KB
/
NouException.cpp
File metadata and controls
109 lines (90 loc) · 2.21 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
104
105
106
107
108
109
#include "NouException.h"
#include <sstream>
//BASE EXCEPTION
NouException::BaseException::BaseException(int line, const char* file) noexcept
:
line(line),
file(file),
text("None")
{
}
NouException::BaseException::BaseException(int line, const char* file, std::string text) noexcept
:
line(line),
file(file),
text(text)
{
}
const char* NouException::BaseException::what() const noexcept
{
std::ostringstream oss;
oss << GetType() << std::endl
<< GetOriginString();
whatBuffer = oss.str();
return whatBuffer.c_str();
}
int NouException::BaseException::GetLine() const noexcept
{
return line;
}
const char* NouException::BaseException::GetType() const noexcept
{
return "NouEngine Exception";
}
const std::string& NouException::BaseException::GetFile() const noexcept
{
return file;
}
std::string NouException::BaseException::GetOriginString() const noexcept
{
std::ostringstream oss;
oss << "[Text] " << text << std::endl
<< "[File] " << file << std::endl
<< "[Line] " << line;
return oss.str();
}
//HR EXCEPTION
NouException::HrException::HrException(int line, const char* file, HRESULT hr) noexcept
:
BaseException(line, file),
hr(hr)
{}
std::string NouException::HrException::TranslateErrorCode(HRESULT hr) noexcept
{
char* pMsgBuf = nullptr;
DWORD nMsgLen = FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPSTR>(&pMsgBuf), 0, nullptr
);
if (nMsgLen == 0)
{
return "Unidentified error code";
}
std::string errorString = pMsgBuf;
LocalFree(pMsgBuf);
return errorString;
}
const char* NouException::HrException::GetType() const noexcept
{
return "NouWindow Exception";
}
HRESULT NouException::HrException::GetErrorCode() const noexcept
{
return hr;
}
std::string NouException::HrException::GetErrorString() const noexcept
{
return TranslateErrorCode(hr);
}
const char* NouException::HrException::what() const noexcept
{
std::ostringstream oss;
oss << GetType() << std::endl
<< "[Error Code] " << GetErrorCode() << std::endl
<< "[Description] " << GetErrorString() << std::endl
<< GetOriginString();
whatBuffer = oss.str();
return whatBuffer.c_str();
}