-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcException
214 lines (166 loc) · 6.96 KB
/
cException
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' cException (class)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Custom error functionality. Overloaded to include call stack procedures as well.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
'SUBROUTINES
' .Throw 'I/O (Output as MsgBox)
'GENERAL PROPERTIES
Private pFlag As Boolean 'Read/Write
Private pIsError As Boolean 'Read/Write
Private pErrNumber As Integer 'Read/Write
Private pErrDescription As String 'Read/Write
Private pErrMessage As String 'Read/Write
'CALL STACK PROPERTIES
' .Push 'Write only
' .Pop 'Removes the Last-In item on the call stack
' .StackEmpty 'Returns boolean
' .StackTop 'Returns variant (string)
Public siTop As StackItem 'For internal use
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' SUBROUTINES
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub Throw(Optional ByVal Resolution_Message As String = "Resolution: Unknown")
On Error Resume Next
Dim Str As String
Dim insertMessage As String
Debug.Print "WARNING: An Exception has been thrown"
Debug.Print Space(5) & "Custom Message: " & Resolution_Message
'''''''''''''''''''''''''''
' Settings
'''''''''''''''''''''''''''
On Error GoTo SkipLogProcedure
Err.Clear
insertMessage = Resolution_Message
'''''''''''''''''''''''''''
' Present MessageBox
'''''''''''''''''''''''''''
If Me.IsError = True Or Me.Flag = True Then
Str = insertMessage & vbNewLine & vbNewLine & _
"Error occurred during procedure: " & Me.StackTop & vbNewLine & vbNewLine & _
Me.ErrMessage
If Not Me.ErrNumber = 0 Then
Str = Str & vbNewLine & vbNewLine & "Error # " & Me.ErrNumber & ": " & Me.ErrDescription
End If
MsgBox Str, vbCritical, "An error has occurred"
Else
Str = insertMessage & vbNewLine & vbNewLine & _
"Failure occurred during procedure: " & Me.StackTop & vbNewLine & vbNewLine & _
Me.ErrMessage
MsgBox Str, vbInformation, "An error has occurred"
End If
'''''''''''''''''''''''''''
' Cleanup
'''''''''''''''''''''''''''
Cleanup:
Debug.Print "END Exception.Throw"
Exit Sub
'''''''''''''''''''''''''''
' Error Handler
'''''''''''''''''''''''''''
SkipLogProcedure:
If Me.IsError = True Or Me.Flag = True Then
Debug.Print "WARNING: AN ADDITIONAL ERROR HAS OCCURRED WITHIN THE cException.Throw PROPERTY"
Str = insertMessage & vbNewLine & vbNewLine & _
"Error occurred during procedure: " & Me.StackTop & vbNewLine & vbNewLine & _
Me.ErrMessage
If Not Me.ErrNumber = 0 Then
Str = Str & vbNewLine & vbNewLine & "Error # " & Me.ErrNumber & ": " & Me.ErrDescription
End If
MsgBox Str, vbCritical, "An error has occurred"
Else
Debug.Print Space(5) & "WARNING: AN ADDITIONAL ERROR HAS OCCURRED WITHIN THE Exception.Throw PROPERTY"
Str = insertMessage & vbNewLine & vbNewLine & _
"Failure occurred during procedure: " & Me.StackTop & vbNewLine & vbNewLine & _
Me.ErrMessage & vbNewLine & vbNewLine & _
"WARNING: AN ERROR HAS ALSO OCCURRED WITHIN THE ERROR HANDLING PROCEDURE"
MsgBox Str, vbInformation, "An error has occurred"
End If
Resume Cleanup
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' GENERAL PROPERTIES
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' .Flag property
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Property Let Flag(Value As Boolean)
pFlag = Value
End Property
Public Property Get Flag() As Boolean
Flag = pFlag
Debug.Print Space(15) & "Exception.Flag = " & CStr(pFlag)
End Property
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' .IsError property
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Property Let IsError(Value As Boolean)
pIsError = Value
End Property
Public Property Get IsError() As Boolean
IsError = pIsError
Debug.Print Space(15) & "Exception.IsError = " & CStr(pIsError)
End Property
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' .ErrNumber property
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Property Let ErrNumber(Value As Integer)
pErrNumber = Value
End Property
Public Property Get ErrNumber() As Integer
ErrNumber = pErrNumber
Debug.Print Space(15) & "Err Number: " & CStr(pErrNumber)
End Property
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' .ErrDescription property
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Property Let ErrDescription(Value As String)
pErrDescription = Value
End Property
Public Property Get ErrDescription() As String
ErrDescription = pErrDescription
End Property
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ErrMessage property
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Property Let ErrMessage(Value As String)
Debug.Print Me.StackTop & " || " & CStr(Value)
pErrMessage = Value
End Property
Public Property Get ErrMessage() As String
ErrMessage = pErrMessage
End Property
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' STACK PROPERTIES AND PROCEDURES
'The following code is courtesy of the MSDN
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub Push(ByVal varText As Variant)
' Add a new item to the top of the stack.
Debug.Print "Starting the " & varText & " routine"
Dim siNewTop As New StackItem
siNewTop.StackValue = varText
Set siNewTop.NextItem = siTop
Set siTop = siNewTop
End Sub
Public Function Pop() As Variant
If Not StackEmpty Then
' Get the value from the current top stack element.
' Then, get a reference to the new stack top.
Debug.Print "Ending the " & Me.StackTop & " routine"
Pop = siTop.StackValue
Set siTop = siTop.NextItem
End If
End Function
Property Get StackEmpty() As Boolean
' Is the stack empty? It can
' only be empty if siTop is Nothing.
StackEmpty = (siTop Is Nothing)
End Property
Property Get StackTop() As Variant
If StackEmpty Then
StackTop = Null
Else
StackTop = siTop.StackValue
End If
End Property