2
votes

There is some old legacy vbscript code we have that needs some sort of error handing in it. Having never used vbscript before, I'm at a total loss. Here is the code:

set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkload.4.0")
objBL.ConnectionString = "connectionstring"
objBL.KeepIdentity = false
objBL.ErrorLogFile = "E:\code\Acquity\WebOrderImport\logs\error.log"

Set fso = CreateObject("Scripting.FileSystemObject")
Set parentfolder = fso.GetFolder("E:\textdata\Acquity\AcquityWebOrders")  
Set logfile = fso.OpenTextFile("E:\code\Acquity\WebOrderImport\logs\import.log",8)
count = 0
    For each folder in parentfolder.subfolders
        logfile.writeline count & " files"
        logfile.writeline "Processing " & folder.name & " ***********************************" & now()
        count = 1
        For Each file in folder.files
            If left(file.name,6) = "Order_" then
                If left(file.name,13) = previous then
                    logfile.writeline "!!!!! SKIPPING file " & file.name & "!!!!! DUPED ORDER ID"
                Else
                    logfile.writeline "reading " & file.name        
                    objBL.Execute "E:\code\Acquity\WebOrderImport\acq_WebOrder_import.xsd", file.path                   
                    count=count+1
                End If  
            previous = left(file.name,13)
            End If
        Next
    Next    

set objBL=Nothing
logfile.writeline "Done!"
Set logfile = nothing
Set parentfolder = nothing
set fso = nothing

I'm pretty sure this line:

bjBL.Execute "E:\code\Acquity\WebOrderImport\acq_WebOrder_import.xsd", file.path

keeps throwing exceptions, and I need the code to keep running when it hits an error, rather than stopping. How can I do this?

3

3 Answers

5
votes

To ignore errors, add On Error Resume Next before the part that can cause them. To disable the effect of "resume next", use On Error Goto 0.

3
votes

For a quick and (very) dirty way to get the code to keep running, you can add On Error Resume Next to the top of the file, and execution will happily carry on when it hits an error.

2
votes

I have a little practice with this technology, but AFAIK vbscript has only one way to handle runtime-exceptions: On Error Resume Next.

You can read these articles: MSDN article and more helpful for me about handling and notifying.