-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTUN_Error.h
executable file
·116 lines (70 loc) · 1.75 KB
/
TUN_Error.h
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
// TUN_Error.h: Interface of class CErr.
//
// (C)opyright in 2009 by Mark Henning, Germany
//
// Contact: See contact form at www.mark-henning.de
//
// This class provides basic error handling.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_TUN_ERROR_H__26166046_5A6B_488C_B226_71921493B2E2__INCLUDED_)
#define AFX_TUN_ERROR_H__26166046_5A6B_488C_B226_71921493B2E2__INCLUDED_
#include <string>
namespace TUN
{
class CErr
{
public:
CErr()
{
SetOK();
}
virtual ~CErr()
{
}
// Checks for OK
bool IsOK() const
{
return m_strErrorMsg.empty();
}
// Returns error message
std::string GetLastError() const
{
return m_strErrorMsg;
}
// Set the error message
// SetError(NULL) works like SetOK() as it clears the error message and
// returns true. If szErrorMsg != NULL, error message is set and
// return value is false.
bool SetError(const char * szErrorMsg, long lLineNr = -1)
{
if ( szErrorMsg == NULL )
m_strErrorMsg = "";
else
{
// 012345
char sz[16] = "Line 1234567890"; // Enough for 32-Bit
if ( lLineNr >= 0 )
// CHANGED: Removed ltoa usage
// Original usage: ... ltoa(lLineNr, &sz[5], 10) ...
m_strErrorMsg = "Line " + std::to_string(lLineNr) + ": " + szErrorMsg;
else
m_strErrorMsg = szErrorMsg;
}
return IsOK();
}
bool SetError(const CErr & err)
{
*this = err;
return IsOK();
}
// returns always true
bool SetOK()
{
return SetError(NULL);
}
private:
std::string m_strErrorMsg;
};
} // namespace TUN
#endif // !defined(AFX_TUN_ERROR_H__26166046_5A6B_488C_B226_71921493B2E2__INCLUDED_)