Examples: LogError method
- This script logs a Domino® error
to a file. The lsERR_NOTES_DATABASE_NOTOPEN error occurs when a database
cannot be opened; here, it occurs if Domino® cannot
locate the current user's mail database after the call to the OpenMail
method. If this happens, control passes to the logDbOpenError label,
and the error code and string get placed into the file LOG.TXT. For
example, the line in LOG.TXT looks like this:
Ornithology Agent: 10/25/95 02:48:40 PM: Error (4063): Unable to open db CPycha.nsf
This script must include the file LSXLERR.LSS in order to use the Domino® error constants.
Sub Initialize On Error lsERR_NOTES_DATABASE_NOTOPEN Goto logDbOpenError Dim currentLog As NotesLog Dim db As NotesDatabase Dim collection As NotesDocumentCollection Set currentLog = New NotesLog( "Ornithology Agent" ) Set db = New NotesDatabase( "", "" ) Call db.OpenMail Call currentLog.OpenFileLog( "c:\log.txt" ) Set collection = db.AllDocuments ' error might occur here Call currentLog.Close Exit Sub logDbOpenError: Call currentLog.LogError _ ( lsERR_NOTES_DATABASE_NOTOPEN, _ "Unable to open db " & db.FileName ) Resume Next End Sub
- This script logs a user-defined error to a file. The script performs
a full-text search on the current database, looking for the word "Rocks."
If it does not find any matching documents, the script logs an error
to another database on the same computer. Neither Domino® nor LotusScript® considers this condition
to be an error, but you can use the LogError method to log any condition
that prevents the successful completion of a script.
Sub Initialize Dim currentLog As NotesLog Dim session As New NotesSession Dim db As NotesDatabase Dim collection As NotesDocumentCollection Dim doc As NotesDocument Set currentLog = New NotesLog( "Geology Agent" ) Call currentLog.OpenNotesLog( "", "agentlog.nsf" ) Set db = session.CurrentDatabase Set collection = db.FTSearch( "Rocks", 0 ) If ( collection.Count = 0 ) Then Call currentLog.LogError( 0, "No documents found." ) Else Set newsletter = New NotesNewsletter( collection ) Set doc = newsletter.FormatMsgWithDoclinks( db ) Call doc.Send( False, "Thalia Ruben" ) End If Call currentLog.Close End Sub
- This agent script logs a LotusScript® error
to a mail memo. The error ErrDivisionByZero occurs when a script attempts
to divide a number by zero. When this happens, control passes to the
LogThisError label, where the LogError method adds a line of text
to the body of the mail memo, which looks like this:
10/25/95 04:58:29 PM Let's do division starting 10/25/95 04:58:29 PM Error (11): Division by zero
This script must include the file LSERR.LSS in order to use the LotusScript® error constants.
Sub Initialize On Error ErrDivisionByZero Goto LogThisError Dim currentLog As New NotesLog( "Let's do division" ) Dim x As Integer, y As Integer, z As Integer Call currentLog.OpenMailLog _ ( "Joe Perron", "Division log" ) y = 9 z = 0 x = y / z ' error Call currentLog.Close Exit Sub LogThisError: Call currentLog.LogError( ErrDivisionByZero, _ Error$( ErrDivisionByZero ) ) Resume Next End Sub
- The call to OpenMailLog in the third script is replaced
with the following:
Call currentLog.OpenNotesLog( "", "agentlog.nsf" )
In this case, the LogError method creates a new document in AGENTLOG.NSF. The document contains the following items:
A$PROGNAME "Let's do division" A$LOGTIME 10/25/95 04:42:24 PM A$USER "Kerry Bowling" A$LOGTYPE "Error" A$ERRCODE 11 A$ERRMSG "Division by zero"
- The call to OpenMailLog in the third script is replaced
with the following:
Call currentLog.OpenFileLog( "c:\log.txt" )
The LogError method adds a new line of text to LOG.TXT. For example, LOG.TXT looks like this:
Let's do division: 10/25/95 04:49:51 PM: Error (11): Division by zero