2

I'm a little lost as to how to continue the program execution with this LotusScript snippet. It extracts all the documents from a view, however, it is hitting a certain document that contains an 'Overflow' error which stops the program, rather than ignoring this and continuing to the next document. The error message is being printed out, so it's clear that the code is entering the ErrorHandler, and then subsequently ends.

Option Public
Option Declare

Sub Initialize
    'init stuff, etc

    Set view = db.getView("Main")
    Set doc = view.getFirstDocument()
    Set lastDoc = view.getLastDocument()
    k = 0

    While (Not doc is Nothing)
        dealId = doc.DealId(0)
        If(doc.HasEmbedded) Then 
            Set body = doc.GetFirstItem("Body")         
            If(Not body Is Nothing) Then 
                'code to extract all attachments on a document
            End If
        End If

nextDoc:
        Set doc = view.getNextDocument(doc)
        k = k + 1
    Wend    
    Exit Sub 

errHandler:
    Print "Get error when process document with dealId=" & dealId & " at line " & CStr(Erl) & ". Err=" & CStr(Err) & ", error=" & Error
    GoTo nextDoc
    'this should continue execution of nextDoc
End Sub
Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
logeyg
  • 549
  • 2
  • 8
  • 31
  • 1
    Although the question has been answered, it doesn't address the root cause of why you're getting the overflow in the first place. Is it in the code removed, or is it K overflowing because it's an integer and has exceeded 32k? Or are there some other arithmetic calculations going on that mean your variable types need to be reviewed? – Simon Delicata Jan 14 '16 at 22:34
  • @FruitySoup no idea. I'm simply extracting attachments from a database - not arithmetic operations. I continually ran into one in particular, so maybe the file size was overly large? – logeyg Jan 18 '16 at 15:17

1 Answers1

4

Add a line

On Error GoTo errHandler

before While and replace line after Print with

Resume nextDoc

Your code might cause an infinite loop though. If for example view "Main" is not available, the line
Set view = db.getView("Main") would cause an error. Execution would jump to errHandler and from there to nextDoc. The line Set doc = view.getNextDocument(doc) would throw an error too as doc is Nothing. Execution would jump to errHandler and from there to nextDoc and... we have an infinitive loop.

You can avoid this with an error handling like this:

nextDoc:
        Set doc = view.getNextDocument(doc)
        k = k + 1
    Wend    

finito:
    Exit Sub 

errHandler:
    If doc is Nothing then
        Print "This is a serious error before while..."
        Resume finito
    Else
        Print "Get error when process document with dealId=..."
        Resume nextDoc
    End If
End Sub
Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • I did have the 'On Error Goto errHandler' in the init section, but was using GoTo nextDoc instead of Resume. Why does that make a difference? – logeyg Jan 14 '16 at 16:12
  • 1
    `Resume` "forgets" the error and continues on nextDoc like there never has been an error. `GoTo` just jumps to nextDoc but the error is still "active". – Knut Herrmann Jan 14 '16 at 16:36