-
Notifications
You must be signed in to change notification settings - Fork 76
/
exceptions.h
107 lines (79 loc) · 3.06 KB
/
exceptions.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
#pragma once
/////////////////////////////////////////////////////////////////////////////
// CSystemException
void ThrowSystemException(DWORD dwError = 0);
class CSystemException : public CException
{
// Construction
DECLARE_DYNAMIC(CSystemException)
public:
CSystemException(DWORD dwError);
// Attributes
public:
DWORD m_dwError;
// Implementation
public:
virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError, PUINT pnHelpContext = NULL);
};
/////////////////////////////////////////////////////////////////////////////
// CErrorException
void ThrowErrorException(UINT nFormatID, ...);
void ThrowErrorException(LPCTSTR lpszFormat, ...);
class CErrorException : public CException
{
// Construction
DECLARE_DYNAMIC(CErrorException)
public:
CErrorException(LPCTSTR lpszFormat, ...);
CErrorException(UINT nFormatID, ...);
// Attributes
public:
CString m_strError;
// Implementation
public:
virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError, PUINT pnHelpContext = NULL);
};
/////////////////////////////////////////////////////////////////////////////
// CHECKHRESULT_EXCEPTION
// Use this for calls which return the high-order bit set on an error (ie. on a COM
// call).
struct CHECKHRESULT_EXCEPTION
{
CHECKHRESULT_EXCEPTION (HRESULT hr = 0) { if (FAILED(hr)) ThrowSystemException (hr); }
HRESULT operator = (HRESULT hr) { if (FAILED(hr)) ThrowSystemException (hr); return hr; }
};
/////////////////////////////////////////////////////////////////////////////
// CHECKOSSTATUS_EXCEPTION
// Use this for calls which return 0 if successfull, but on failure the error is
// returned directly.
struct CHECKOSSTATUS_EXCEPTION
{
CHECKOSSTATUS_EXCEPTION (long i = 0) { if (i != 0) ThrowSystemException (i); }
long operator = (long i) { if (i != 0) ThrowSystemException (i); return i; }
};
/////////////////////////////////////////////////////////////////////////////
// CHECKZERO_EXCEPTION
// Use this for calls which return 0 if successfull, but on failure the error is
// returned in GetLastError ()
struct CHECKZERO_EXCEPTION
{
CHECKZERO_EXCEPTION (long i = 0) { if (i != 0) ThrowSystemException (); }
long operator = (long i) { if (i != 0) ThrowSystemException (); return i; }
};
/////////////////////////////////////////////////////////////////////////////
// CHECKNONZERO_EXCEPTION
// Use this for calls which return non-zero if successfull, but on failure the error is
// returned in GetLastError ()
struct CHECKNONZERO_EXCEPTION
{
CHECKNONZERO_EXCEPTION (long i = 1) { if (i == 0) ThrowSystemException (); }
long operator = (long i) { if (i == 0) ThrowSystemException (); return i; }
};
/////////////////////////////////////////////////////////////////////////////
// CHECKNOTMINUSONE_EXCEPTION
// Use this for calls which return -1 on an error, but any other value if OK.
struct CHECKNOTMINUSONE_EXCEPTION
{
CHECKNOTMINUSONE_EXCEPTION (long i = 0) { if (i == -1) ThrowSystemException (); }
long operator = (long i) { if (i == -1) ThrowSystemException (); return i; }
};