-
Notifications
You must be signed in to change notification settings - Fork 0
/
XLException.cpp
64 lines (55 loc) · 1.14 KB
/
XLException.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
#include "common.h"
#include "XLException.h"
std::string XLException::StringErrNo()
{
return StringErrNo(errno);
}
#if _MSC_VER
std::string XLException::StringWindows()
{
return StringWindows(::GetLastError());
}
#endif
std::string XLException::StringErrNo(int errorno)
{
std::stringstream out;
out << "errno:" << errorno << " info:";
#ifdef __STDC_WANT_SECURE_LIB__
char buffer[1024];
strerror_s( buffer , sizeof(buffer)-1, errorno);
buffer[sizeof(buffer)-1] = '\0';
out << buffer;
#else
out << strerror( errorno );
#endif
return out.str();
}
#if _MSC_VER
std::string XLException::StringWindows(unsigned long errorno )
{
std::stringstream out;
out << "GetLastError:" << errorno << " info:";
void* msgBuf;
::FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
errorno,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // デフォルト言語
(LPTSTR) &msgBuf,
0,
NULL
);
if (msgBuf == NULL)
{
out << "can not found error!";
}
else
{
out << msgBuf;
}
return out.str();
}
#endif