I have a script that loops through all the filenames in an array and checks to see if they exist, then does some other ‘stuff’. I’m having a problem if a particular folder doesn’t exist. The first time it comes across a folder that doesn’t exist, the error handling works, and it goes to the place I direct it. The second time it comes across a folder that doesn’t exist, agent execution ends with a “Path Not Found” error as if there were no error handling. Here’s the code that is causing the problems. What did I do wrong? How can I change it so the error will be handled each time?
Forall infxFilePath In uInfxFiles
fileExist = “”
On Error Goto pathNotFound
fileExist = Dir$(pathPrefix & infxFilePath) 'error handling is not working. Works first time through. Second time, errors out
If fileExist <> “” Then 'file exists
'do nothing, this is OK
Else
'do something else
End If
Not many ideas from me really, only thing I would suggest is that when I expect/know a certain error is going to be encountered I accommodate for it by stating the specific error number as below.
On Error 1234 Goto HandleErr
This may prove to be more explicit when catching this error. Please let me know if this has any relevant effect as this intrigues me!!
Probaly wont make a difference. Out of interest have you got more then one “on Error GoTo…” line of syntax? This could be a cause of a problem as you describe if it was encountering the first(correct handling) then seeing the second ‘On Error…’ command. As the second instruction will overwrite the initial one.
Thanks! I haven’t tried it because I finally got something working (after hours of playing with it)! For some reason it didn’t like the “on error goto pathNotFound” line. Once I removed that line and just left an “on error goto errHand” line at the top of my agent. Then errHand code is:if err = 76 then
'path not found do something
else
'other error - do something else
end if
Works fine. Not sure why it didn’t work the other way, but this is working and actually easier to follow in the case of an error so I’m probably better off.