I have a few lines of code wrapped in two write log events. I know that the first part of the code is happening because I can see the first entry of the log that says the process has started but the entry that says the process completed is not being written. Somewhere in the code an error is being thrown but the error handler is not catching it for some reason. I've tried checking the event viewer for any logs about my application that Windows may have written, like it causing a crash or Windows closing it for some reason but there's nothing there. Is there a way that VB6 would skip an error handler and if so, how could I find evidence of it?
My code looks something like this:
On Error GoTo ErrorHandler
Dim fso As FileSystemObject
Dim DirPattern As String
Dim FileName As String
Dim DaysOld As Integer
' Init log name to ensure Today's value will be put in there
g_PurgeLogName = ""
Call WriteToLog("Purging of Text Files Started")
sql = "SELECT * FROM [Text File Purge Profiles] " & _
"WHERE User = '" & g_User & "' " & _
"ORDER BY ProfileName;"
Dim rs As ADODB.Recordset
Set rs = ic.RsReadOnly(cnMF, sql)
With rs
Do While Not .EOF
Set fso = New FileSystemObject
' create dirPattern to use with "Dir" command
DirPattern = fso.BuildPath(!PurgePath, !FileMask)
' get first file matching this pattern
FileName = Dir(DirPattern)
Do While Len(FileName)
FileName = fso.BuildPath(!PurgePath, FileName)
' how many days ago was this file created?
DaysOld = DateDiff("d", fso.GetFile(FileName).DateCreated, Now)
If DaysOld > !RetainDays Then
Debug.Print "Deleting " & FileName
fso.DeleteFile FileName, True
DoEvents
End If
' get next file matching this pattern
FileName = Dir
Loop
.MoveNext
Loop
.Close
End With
Call WriteToLog("Purging of Text Files Completed")
Set fso = Nothing
Set rs = Nothing
Exit Sub
'=============
ErrorHandler:
'=============
Call MsgBox2("An error occured while trying to process the Text File purge" & _
vbLf & vbLf & err.Number & ": " & err.Description, vbCritical)
Call WriteToLog("Text File Purge did not complete")
Call WriteToLog(vbTab & err.Number & ": " & err.Description)
Call ClearScreen
Call err.Clear
I can see that there could be issues with deleting files the program doesn't have permission to access or that there could be an issue with the query somehow but as far as I can tell, any problems that could arise should be handled by the error handler and the log would still have more text than the "process started" bit.