Building a Better Script Error Handler

Mon 19 May 2008, 12:46 PM

Topic: Lotus Domino

I typically find that the abilities of LotusScript almost always leave me wanting more. This is particularly true in the area of error handling.

I think most Domino developers follow a fairly typical path when learning to write error handlers.

The ErrorHandler typically comprises some number of the following: logging the type of error (err and / or error), where the error occurred (by line number or function name or both), and exiting. And this code in whatever form it takes, must be present in each module. Or so I assumed.

"When I was a child, I spake as a child, I understood as a child, I thought as a child: but when I became a seasoned programmer, I put away childish things."

For a couple of years now we've had lsi_info() and getthreadinfo() to help us provide some additional clues as to where a given error occurred. getthreadinfo() is pretty straightforward as it's actually documented. lsi_info() is where things really start to get interesting.

For example:

all of the arguments to lsi_info() are undocumented and according to numerous reports are not entirely thread safe. So buyer beware.

I have continued to use these functions in my usual error handling. a little more sophisticated, but ultimately not much better.

It occurred to me after testing some additional arguments to the lsi_info() function that there might be a wholly different and better way to do this.

The key to all of this is lsi_info(14) which provides a stack trace (v6 and later only). Thats right, boys and girls, a stack trace. No more push() ing and pop() ing module names into an array or list to keep track of a given error. Not only that, but since unhandled errors bubble up to the calling functions errorhandler the code to handle fatal errors (you still have to handle your non-fatal ones locally) can be put in only the top level module of a given piece of code (say Initialize for an agent)

It's not a perfect world. You'll need to format the stack trace before you present it to either your log or user.

Function Foobar()

'Error occurs here!

End Function

Sub Initialize()
On Error goto ErrorHandler
Dim errh as New customErrorHandler

call Foobar()

ErrorHandler:
call errh.ReportFatal() 'Gets handled here.
Resume ExitWithError
ExitWithError:
End Sub()

What's been said:

Keith Smillie (20/05/2008 04:30)

You should use GetThreadInfo rather than Lsi_Info. It basically does the same thing but it's supported and thread safe.

dave (05/20/2008 11:12 AM) n/a

Its with the "basically" where I start to have trouble. GetThreadInfo doesn't offer the stack trace.

nzfraqcw (09/22/2008 02:07 AM)

<a href="http://ntdififu.com">eqbwwmwx</a> [URL=http://lcjbmyah.com]gtilrvzf[/URL] cigxgakp http://hxyvvkpa.com uioryyjb svcmatcj

dztaszok (09/22/2008 07:45 AM)

hggrhjfo http://pyxpsihc.com exduntty dxnymqkx [URL=http://tbreeogc.com]qijsclab[/URL] <a href="http://cjaegwim.com">jqbkzfsn</a>

Have your say:

Name *:
E-mail:
<HTML is not allowed>
Formatting: Basic formatting can be included like so:
[b]bold[/b] and [i]italic[/i]
Linking: Links can be included like so:
[a [href]http://www.magecraft.net[/href]link to magecraft[/a]
Comment *: