On Error Goto Lotusscript
Contents |
API Documentation This category Redbooks Wiki: Best Practices for Domino 8.0 Web Application Development Redbooks Wiki: Building Domino Web Applications using Domino 8.5.1 Redbooks Wiki: Creating Plugins for Lotus Notes, Sametime, and Symphony Redbooks Wiki: Lotus Domino Development Best Practices Custom Search Scope... Search Community Articles > Troubleshooting > Handling errors in LotusScript New Article Share ▼ Subscribe ▼ About the Original AuthorDeanna DrschiwiskiContribution Summary:Articles authored: 76Articles edited: 227Comments Posted: 8 Recent articles by this author Getting started with XPages Need help getting started with XPages? This guide provides links to overview content, videos, tutorials, and other content http://www.ibm.com/support/knowledgecenter/SSVRGU_9.0.0/com.ibm.designer.domino.main.doc/LSAZ_ON_ERROR_STATEMENT.html that will get you up to speed quickly. XPages Domino Object Map 8.5.2 This topic contains a map of the domino objects contained in XPages. Best practice to develop a good Notes application from the globalization perspective This presentation shows the best practice to develop a good Notes application from the globalization perspective Introducing of Domino Global WorkBench 8.5 This presentation shows how to localize https://www-10.lotus.com/ldd/ddwiki.nsf/dx/09122008112520AMDDRPLW.htm Domino templates with Domino Global WorkBench 8.5 XPages Extensibility API Developers Guide Welcome to the XPages Extensibility API Developers Guide; the Official Resource for Development using the XPages Extensibility API. Handling errors in LotusScriptAdded by Deanna Drschiwiski | Edited by Deanna Drschiwiski on October 30, 2009 | Version 8 Edit More Actions ▼ 1 comment AbstractAbstractNo abstract provided.Tags: troubleshooting, LotusScript, agents, error handling, getting started, new user, samples This article is targeted to newer LotusScript developers. You can use error handling in LotusScript agents to both troubleshoot and gracefully handle exceptions at runtime. Here is a "shell" for implementing error handling in a LotusScript agent. Sub Initialize 'The following line says to jump to the label called ErrorHandler if there is an error. On Error Goto ErrorHandler Dim s As New NotesSession Dim thisAgent As NotesAgent 'This is used to obtain the name of the agent currently running. Set thisAgent = s.CurrentAgent 'Your code goes here 'The Done label is there so you can reference it in your ErrorHandler. 'The Exit Sub jumps past the ErrorHanlder if the code above successfully completes. Done: Exit Sub ErrorHandler: 'The Select statement enables you to
Type mismatch errors when all you were doing was going about your normal business. Well, these errors are often down to poor / non-existent error handling on the part http://benpoole.com/weblog/200212020837 of the coder. Here's how to avoid that kind of nonsense… On Error http://www.codestore.net/store.nsf/unid/DOMM-4PUCML?OpenDocument Goto… Lotusscript is a procedural, or linear language. By this I mean that your code kicks off, and runs, bumpity-bumpity-bump to the end. Sure, there can be some branching and stuff like that, but ultimately it's a BASIC-derived language, and therefore linear (object models and the like notwithstanding). This means that you can on error often see the dreaded Goto statement dotted around (note: the link is a 123KB PDF) Now, I don't particularly like to use the Goto statement, but sometimes we don't have much choice. Whilst I like to break up reams of impenetrable code into nice logical parcels held within sub-routines and functions, I have to use the Goto statement to cover my arse with regards errors. The on error goto line you may be aware of is this: On Error Goto lblErrs Forget the "lblErrs" bit for the time being -- that's just a custom "label" I use for the actual error handling code -- but I'm sure you can see what we're telling the program to do here. As soon as an error is hit, go to the named label. Why do we have labels? Well, some of you may well remember the heady days of early '80s BASIC programming on ZX Spectrums, BBC Micros, and the like. I think just about everyone went into their local electronics store and did something like this to the demo machines: 10 Print "Ben woz 'ere";
20 Goto 10 Oh how we laughed. Well, back then we had BASIC programs with line numbering. In Lotusscript and VB we only use line numbers for referencing, we don't use them within the actual code (apart from maybe in error handlers, when we use the Erl function), so we have labels instead. Time for some sample code to illustrate this I think. On Error Goto lblErrs
Dim session As New NotesSession
Dim db As NotesDatabase
Dim vw As NotesView
Dim doc A
lucky if you are even aware of it. The "Agent Done" message is probably the closest clue you'll receive. That is why it is often a good idea to include some kind of error handling in every agent that you intend to run via a browser. To do this start every agent with the line: On Error Goto ErrorHandler Then at the bottom of the Initialise event place the following label and code: ErrorHandler:
Call PrintErrorMsg("Code - " & Str(Err) & ": " & Error$ + ". (onLine " & Str(Erl) & ").", True) This then calls a subroutine that "prints" the error message back to the user/designer. The second argument to this routine is a boolean that tells it whether to quit execution or not. This can depend on the severity of the error and lets you call the routine from any point in the code, not just when an error occurs. Code for this routine is: Sub PrintErrorMsg(errMsg As String, fatal As Integer)
Print {
An error has occured in the application.
Please report the following message to the system administrator:
} & errMsg & {
Click here to return:
Return
}
If fatal Then End
End Sub Note: I usually place PrintErrorMsg in a ScriptLibrary so that all of my agents can share it. Once you have found that there is indeed an error in your code and you know, roughly, where and what it is, you are probably going to have to find out what's causing it. The best way to do this is to use lines of code that simply print lines of text at specific locations and see which of these actually gets printed. For example the following code produces an error: print "i am here
"
anInt% = otherInt%
print "i got past line 1
"
anInt% = aString$
print "i got past line 2
" This will produce two lines of text, "i am here" and "i got past line 1", followed by an error message about a Type Mismatch (I tried to compare two different types! woops). The result will look something like: It is obvious from this which line the error has occured on. It also warns the user that things maybe aren't going as planned and to not presume the action was taken. Feedback Johan Känngård Tue 10 Oct 2000 Hidden functions in LotusScriptThere is a "hidden" function in LotusScript, Lsi_Info. This contains