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.
1) Create a new agent, and include the following code. 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 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 Case Else '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 Resume Done End Select End Sub
2) Enter your agent code under the line labeled "Your code goes here"
3) Use the errors that display as you continue developing your solution to debug your agent, or to gracefully handle certain run-time conditions.
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 ... Exit Function errHandler: Error Err, Error & | | & Lsi_info(2) & |/| & Erl Exit Function
__ end of some function
No logging is nece
ssary in functions, becase there is an "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.