Domino Code Fragment

Code Name*
Create error handling class
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.145.163.58
Description*
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
The only real change in moving HandleErr from Visual Basic to LotusScript is that the object is destroyed explicitly with the Delete objErr statement.
Files/Graphics attachments (if applicable): Code:
The following example shows how to create and use a LotusScript class to create an error handling object. This will demonstrate the use of the HandleErr ( ) function in error processing.
We’ll show the class ErrObject, which will be used to hold and display errors. This code was ported from Visual Basic and the comments following the class describe the changes that were made to allow the port.
This is followed by the actual HandleErr function call; that would be called by the code in our error-handling discussion earlier.
Class ErrObject
Private mErrLogFile As String
Private mErrNumber As Long
Private mErrMsg As String
Private mErrLocation As String
Private mErrLogMethod As Integer
Private mErrSeverity As Integer ' change dim to private
Public Property Get ErrMsg
ErrMsg = mErrMsg
End Property
Public Property Get ErrNumber
ErrNumber = mErrNumber
End Property
Public Property Set ErrNumber ' changed let to set
mErrNumber = ErrNumber
End Property
Public Property Set ErrMessage ' changed let to set
mErrMsg = ErrMessage
End Property
Public Function PostError(ErrNumber As Variant,
ErrLocation As Variant, LogMethod As Variant) As Integer
' pulled the optionals and boolean
PostError = RESUME_NEXT_AFTER_ERR
' use object properties if parameters were ommitted.
If Isempty(ErrNumber) Then ErrNumber = mErrNumber
If Isempty(ErrLocation) Then ErrLocation = _
mErrLocation
If Isempty(LogMethod) Then LogMethod = mErrLogMethod
' build the message. Note, DB, file output may differ
' slightly, as Date/Time, Err, etc may be written to
' separate columns (fields)
mErrMsg = Error$(ErrNumber) & " (#" & _
Format$(ErrNumber) & ") " & "occurred at " & _
Format$(Now, "mm-dd-yy hh:mm:ss") _
& "; at location->" & ErrLocation & "."
Select Case LogMethod
Case LOG_DISPLAY_MESSAGE
Beep
Msgbox (mErrMsg)
Case LOG_TO_DISK
Dim iLogPtr%
iLogPtr% = Freefile
Open mErrLogFile$ For Append Access _
Write As #iLogPtr%
Print #1, mErrMsg
Close #iLogPtr%
Case LOG_TO_DB
' not implemnented
Case LOG_SEND_TO_PAGER
' not implemented
Case LOG_SEND_EMAIL
' not implemented
Case Else
Msgbox (mErrMsg)
End Select
Select Case ErrNumber
Case 5 ' invalid procedure call
ErrSeverity = RECOVERABLE
PostError = SHUTDOWN_AFTER_ERR
Case 68 ' device not available (like when user
' accesses A: without a diskette. Show a
' message and then resume.
ErrSeverity = SHUTDOWN_APP
PostError = RESUME_AFTER_ERR
Case Else
ErrSeverity = RECOVERABLE
PostError = RESUME_NEXT_AFTER_ERR
End Select
End Function
End Class
In moving the code from Visual Basic to LotusScript, we make the following slight modifications.

1. Consts move out of the class into the scope of the object the class is in.
2. Dim statements within the class change to Private.
3. isMissing is not provided. Replace isMissing with isEmpty.
4. Optional arguments are not available. Replace Optional with explicit variable declarations.
5. For property functions, Set is used, rather than Let. Set does not have the special (but rarely used) object passing features that are present in Visual Basic.
Function HandleErr (iErr%, strErrLocation$, iAction%) As Integer
On Error Goto MetaErr
Dim objErr
Set objErr = New ErrObject
rc = objErr.posterror (iErr%, strErrLocation$, iAction%)
Delete objErr
Exit Function
MetaErr:
' An error here might come from a failure to create the object.
Msgbox(Format$(Err) & ", " & Error$(Err))
Resume Next
End Function