ebgreen
-
Total Posts
:
8227
- Scores: 98
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: online
|
Error Persistence Class
Friday, March 09, 2007 3:55 AM
( permalink)
I had written a class similar to this in the past and now I can't find it so I just re-wrote it real quick because someone had requested it. Basically it allows you to keep a running persistent list of error that you won't lose by performing an Err.Clear. Here is the code and I think it is pretty self explanatory, but I can add comments if others don't agree. Option Explicit
Dim oPE : Set oPE = New PersistentErrors
Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim a
Dim oErr
Dim strKey
On Error Resume Next
a = 10/0
oPE.AddError Err, "Division by zero test"
Err.Clear
On Error Resume Next
oFSO.OpenTextFile("C:\foo\bar.txt")
oPE.AddError Err, "Missing file test"
Err.Clear
For Each oErr In oPE.GetErrors()
WScript.Echo "ERROR:"
For Each strKey In oErr.Keys()
WScript.Echo vbTab & strKey & " = " & oErr(strKey)
Next
WScript.Echo ""
Next
Class PersistentErrors
Private arrErrors()
Private nErrorCount
Sub Class_Initialize()
nErrorCount = 0
End Sub
Public Property Get ErrorCount
ErrorCount = nErrorCount
End Property
Public Sub AddError(oError, strComment)
Dim dicTemp
Set dicTemp = CreateObject("Scripting.Dictionary")
dicTemp.Add "Number", oError.Number
dicTemp.Add "Description", oError.Description
dicTemp.Add "HelpContext", oError.HelpContext
dicTemp.Add "HelpFile", oError.HelpFile
dicTemp.Add "Source", oError.Source
dicTemp.Add "Comment", strComment
dicTemp.Add "TimeStamp", Now()
ReDim Preserve arrErrors(nErrorCount)
Set arrErrors(nErrorCount) = dicTemp
nErrorCount = UBound(arrErrors) + 1
End Sub
Public Function GetErrors()
GetErrors = arrErrors
End Function
End Class
|
|
|
|