Manage Learn to apply best practices and optimize your operations.

Use Delete Method To Handle Aborts

This describes a technique for handling unexpected aborts in a LotusScript
program. The specific example is a "FileGuard" class that guarantees that a
file you open gets closed, no matter what else happens.

How it works: whenever you declare a class in LotusScript, you can define a
Delete method that executes when an object of that class is deallocated. This
happens whenever the memory is freed, whether it's because the object has gone
out of scope from the function it was declared in, or because the script
aborted with an error, or by Ctrl+Break.

The simple class below is useful when doing file I/O to make sure that you
don't leave a file open if the user aborts.

Note: you must open a file using the returned file handle from the Handle
method, before you allocate another instance of FileGuard, or else they will
get the same file number. Since Freefile returns the number of the first file
handle that's not yet in use, calling it twice without using the result of the
first call to open a file, returns the same value again.
Class FileGuard
filenumber As Integer
isopen As Integer

Public Property Get Handle
Handle = filenumber
End Property

Sub New()
filenumber = Freefile( )
isopen = True
End Sub

Sub Close
If isopen Then
On Error Resume Next
Close filenumber
isopen = False
End If
End Sub

Sub Delete
End Sub
End Class

Then when you're ready to open a file:

' Keep the next three statements together
Dim FG1 As New FileGuard
outfile% = FG1.Handle
Open "C:\TEMP\DUMP.TXT" For Output As outfile%

Dim FG2 As New FileGuard
infile% = FG2.Handle
Open "\\RAGAMUFFIN\ARGH\TWIST.DAT" For Input As infile%


FG2.Close ' in either order.
This was last published in November 2000

Dig Deeper on Domino Resources - Part 6

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...