Blogs

  • Browse Blogs
  • My Blog
  • My Updates

Tags Help

  • View as cloud  | list

Jan Schulz

Blog Authors:  Jan Schulz  

Previous |  Main  | Next

Extending OpenLog

Jan Schulz  |     |  Comments (0)
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)))
Resume Next

End Function


I'm not yet satisfied: there is still some possibility to refactore code (there is much code duplication in the static methods) and I think most of the setup code (setupLogItem(...) and also for the stackTrace) could go into the classes. Also the dialog could go into a ErrorHandler: just let isResponsible(...) return true if not session.isOnServer and then return false from the handleError(). But this would need some priority in the handlers (no need to ask the user if we can handle it internaly) and a way to indicate if we are in the rethrow phase or in the final handleError()... Let's see....


Another thing is adding Context to the error (also an idea I got from the above example DB...). LogErrorEx(...) already lets you pass in some information, but it would be great if this could be more than a string: something like an object store, some variable values,... No idea yet how to implment that without registering every variable/object in a store :-/ Any Ideas?


Comments

Previous |  Main  | Next
Skip to main content link. Accesskey S
IBM Lotus Connections Help Tools About

Tags

A tag is a keyword that is used to categorize an entry. To view the entries with a particular tag, click a tag name or enter a tag in the box.
The tag cloud indicates the frequency of tag use. Popular tags appear darkest. The slider control adjusts how many tags are displayed in the tag cloud.