I use OpenLog for my error handling and mostly it just works. But there are a few cases, when I wanted to have something more:
- show the error messages to the user and get some information what the user did
- Sending the logentry via mail to the central OpenLog DB in case the user is offline
While I was at it, I also added "Handlers": you can pass in a handler and openlog will ask each handler if the error can be handled (ignored, resolved, etc) by the handler and if so, will return. I got the Idea for error handlers from the "Lotusphere 2008 - AD311 - Object Oriented Programming with Lotusscript – Take It To the Next Level" presentation/ example DB.
Now you can write something like this:
handleerror:
If handleError() Then Resume Next
There is also a new "handleOrRethrowError() method, which corresponds to "addToStackTrace()" but can handle an error.
This handler mechanism are a great way to let someone else extend your code without changing your code. Everything what is needed are some entry points, where you can add you own "HandlerObjects" and of course your code must delegate the handling to it.
This is the new handleError() method I came up with:
Public Function handleError() As Boolean
'** logs whatever error happens to be on the stack (if any)
On Error Goto processError
Dim session As New NotesSession
handleError = False
' First try to handle the error
' Loop over some handler List
' If any can and has handled this error, just return true
Forall handler In errorHandlers
If handler.isResponsibleFor(Err) Then
handleError = handler.handleError()
End If
If handleError = True Then
Exit Function
End If
End Forall
'if not:
' Create a log item and a document
' Ask the user for input with a dialog
Call setupLogItem("","",Nothing,Getthreadinfo(10)) 'refactored to get rid of code duplication
Dim db As NotesDatabase
If session.IsOnServer Then
' I can garantee that there is a OpenLog DB on each server
Set db = GetLogDatabase
globalLogSuccess = globalLogItem.WriteToLog(db)
Else
' local means in most cases not online -> mail it and ask for input
Set db = New NotesDatabase("", "")
Call db.OpenMail
Dim dummyDoc As NotesDocument
Set dummyDoc = globalLogItem.CreateLogDoc(db)
' Just shows a dialog, which displays some fields from the LogItem
If askForAdditionalInformation(dummydoc) Then
globalLogItem.message = globalLogItem.message + Chr(13)+Chr(10)+ dummydoc.GetItemValue("ErrorMessage")(0)
End If
Call dummydoc.Remove(True)
' creates a doc and uses doc.send(...) to mail it to the OpenLog Mail-In DB
globalLogSuccess = globalLogItem.sendViaMail(db)
End If
Call ClearStackTrace()
If Not globalLogSuccess Then
Error 1001, "Log was not saved or sent"
End If
Exit Function
processError:
DebugPrint(StandardErrorMessage(Err, Erl, Error$, Getthreadinfo(1