【问题标题】:Error Handling With LotusScript - Continue Program Execution使用 LotusScript 处理错误 - 继续执行程序
【发布时间】:2016-01-14 15:37:37
【问题描述】:

我对如何使用这个 LotusScript sn-p 继续执行程序有点迷茫。它从视图中提取所有文档,但是,它遇到了包含“溢出”错误的某个文档,该错误会停止程序,而不是忽略这一点并继续下一个文档。错误信息正在被打印出来,所以很明显代码正在进入ErrorHandler,然后随后结束。

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

【问题讨论】:

  • 虽然这个问题已经得到解答,但它并没有解决你为什么会首先出现溢出的根本原因。是在代码中被删除了,还是因为它是一个整数并且超过了 32k 而导致 K 溢出?或者是否有一些其他的算术计算意味着您的变量类型需要审查?
  • @FruitySoup 不知道。我只是从数据库中提取附件 - 而不是算术运算。特别是我经常遇到一个,所以可能是文件太大了?

标签: lotus-notes lotusscript lotus


【解决方案1】:

添加一行

On Error GoTo errHandler

在While之前和Print之后替换行

Resume nextDoc

您的代码可能会导致无限循环。例如,如果视图“Main”不可用,则行
Set view = db.getView("Main") 将导致错误。执行将跳转到 errHandler 并从那里跳转到 nextDoc。 Set doc = view.getNextDocument(doc) 行也会抛出错误,因为 doc 是 Nothing。执行会跳转到 errHandler 并从那里跳转到 nextDoc 并且......我们有一个不定式循环。

您可以通过这样的错误处理来避免这种情况:

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

【讨论】:

  • 我在 init 部分确实有“On Error Goto errHandler”,但使用的是 GoTo nextDoc 而不是 Resume。为什么会有所不同?
  • Resume“忘记”错误并继续执行 nextDoc,就像从未出现过错误一样。 GoTo 只是跳转到 nextDoc 但错误仍然是“活动的”。
猜你喜欢
  • 1970-01-01
  • 2011-08-22
  • 2021-08-22
  • 2020-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多