Bubble up errors - noteslimit

I wanted to bubble up error messages with detailed information about the calling thread. notes truncates the errormessage. Can someone confirm this bound and give me advice how to get around this limit?

this is a (shortended) sample code.

Function test1

On Error Goto ErrorHandler

call test 2

Exit Function

ErrorHandler:

Call raiseError(Err, Error)

Exit Function

End Function

Function test2

On Error Goto ErrorHandler

Error 1003, _

|Write a very long errormasseage here|

Exit Function

ErrorHandler:

Call raiseError(Err, Error)

Exit Function

End Function

Function raiseError (nErr As Integer, sError As String)

If Instr(1,sError, Cstr(nErr)) = 0 Then

	'/* !! Overwrite simple Notesmessage with more detailed message. !! */

	Error nErr, _

	Error$ & " (Error " & Cstr(nErr) & ")" & Chr$(13) + _

	"In '" & Lcase(Cstr(Getthreadinfo(10))) & "' (Line " & Cstr(Erl) & ")."

Else

%REM

'/* !! Doesn’t work for many calls, because Length of Error Messages is limited. !! */

'/* Concatenate Error messages, to get the whole Thread of Calls and bubble up to calling function. */

Error nErr, sError & Chr$(13) + _

“Called from: " +Lcase(Typename(Me)) & “.” & Lcase(Cstr(Getthreadinfo(10))) & " (” & Cstr(Erl) & “).”

%ENDREM

	'/* So we can only bubble up the detailed error desription, but not the thread of calls*/

	Error Err, Error$

End If

End Function 'raiseError

Subject: Bubble up errors - noteslimit

I’m sure there are several ways to overcome any limitations but here’s how I handle errors…

I normally log each error at each level (to an error log [rich-text field upon an execution log document]) and then re-throw the error to ensure that the whole call stack is included in the error text. So the error log would look something like this:

Error at line 9 in NestedFunctionC - ‘Object variable not set’

Error at line 59 in NestedFunctionB - ‘Object variable not set’

Error at line 24 in NestedFunctionA - ‘Object variable not set’

Error at line 14 in Initialize - ‘Object variable not set’

To do this, when an error occurs it is logged (at the level at which it occurs) and is then re-thrown to the error handler in the calling method. The code I use to re-throw the error sits in the error handler block (rather than in the method that writes the error to the rich-text field) and the code to log the error stays in a separate function/method. It’s not much different to how you’re already doing this, except there’s no need to build up a string of the calling stack since each re-throwing of the error logs the information at its current level (including the method name, the error line, and the error message) to the rich-text item. To rethrow the error at each level I clear the error handler (“on error goto 0”) and then rethrow the error (“error err, error$”).

I find it’s easiest to implement all this in OO code rather than procedural code, since OO allows a base class to be defined which contains the HandleError method, along with member variables used for the execution log and its rich-text body field. Then all sub-classes can just include the same error handler in each method which calls the base class handleerror method when anything goes wrong.

I hope this is of some help.

Procedural example:

Sub Initialize

On Error Goto ErrorHandler

'do something

Call NestedFunctionA

ExitPoint:

Exit Sub

ErrorHandler:

HandleError Err, Error$, Erl

'don’t re-throw in module Initialize as there’s no point

Resume ExitPoint

End Sub

Sub NestedFunctionA

On Error Goto ErrorHandler

Call NestedFunctionB

ExitPoint:

Exit Sub

ErrorHandler:

HandleError Err, Error$, Erl

On Error Goto 0 'invoke the calling module’s error handler

Error Err, Error$ 'rethrow the error

End Sub

Sub NestedFunctionB

On Error Goto ErrorHandler

Call NestedFunctionC

ExitPoint:

Exit Sub

ErrorHandler:

HandleError Err, Error$, Erl

On Error Goto 0 'invoke the calling module’s error handler

Error Err, Error$ 'rethrow the error

End Sub

Sub HandleError(PlngError As Long, PstrError As String, PlngLine As Long)

'append the error to a richtext item upon an execution log document (which is kept either as a global variable or a member variable if the methods are part of a class)

'use Getthreadinfo(10) (as you already do) to fetch the name of the module in which the error is being handled

End Sub

Subject: RE: Bubble up errors - noteslimit

Thnak you Phil.This is another interesting way to handle errors.

I found an answer to my question at http://lserror.sourceforge.net/. The limit is not the error statement itself, but the default error-dialog window of Lotus Notes, that truncates the message.