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.
'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.
'The Select statement enables you to handle test for different errors. For example,
'when Err is 53, it indicates "File not found." With some errors, you might choose to
'skip to the next line of code, rather than exiting the entire subroutine.
'For more details, open the "On Error statement" in the Designer help database Index.
Select Case Err
'The next line will document an error, and will include the error number, the agent name,
'the line throwing the error, and the error description.
'The agent name is helpful if this is a web triggered or scheduled agent.
Msgbox "Error " & Cstr(Err) & " in " & thisAgent.Name & " on line " & Cstr(Erl) & ": " & Error
I would also like to point you to some LotusScript Training videos from Lotus Technical Support. These videos offer a great introduction to building and debugging agents using Domino Designer. Please find them using the following link:
Errors should be handled according to situation - do not resolve
error in script called by (unknown) others. Only in top level context or in cycles, resolve it.
Inner functions should use this kind of handler:
__ some function
On Error Goto errHandler
Error Err, Error & |
| & Lsi_info(2) & |/| & Erl
__ end of some function
Should problems occur with the user of LSI_info, remove calls to that function and see if the crashes stop. Instead, use GetThreadInfo, which is a supported LotusScript call. The LSI_info is a Lotus internal function call, and its use may change over time. For an example, please refer to the following Technote:
Title: Server crash on HTTP when using LSI_Info function.
Doc #: 1298407
No logging is necessary in functions, becase there is "error stack" available in Error variable. If you log/prompt it, it will show up why and where error was.
In caller code use common ways of handling. Do not forget to handle errors properly in cycles - you may want not to break cycle just because of minor error in some iteration.