INSERT INTO articles VALUES ('', 'DOMM-4PUCML', 'Agents', '2000-10-09', 'Debugging LotusScript Agents', 'Writing agents that run over the web is not the easiest of tasks if the agent
is anything more than slightly complex.

If you come across an error you\'ll be 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
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 {
<h3>An error has occured in the application.</h3>
<h5>Please report the following message to the system administrator:</h5>
<i>} & errMsg & {</i>
<p />
Click here to return:
<a href=\"$defaultView?OpenView\" target=\"_self\">Return</a>
}

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<br>\"
anInt% = otherInt%
print \"i got past line 1<br>\"
anInt% = aString$
print \"i got past line 2<br>\"


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:

\"Image\"

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.');