First time for error handling... will this work

First time for error handling... will this work

mdhutchinson
Advisor Advisor
295 Views
2 Replies
Message 1 of 3

First time for error handling... will this work

mdhutchinson
Advisor
Advisor
In my application a particular file is deleted with a click event of a check box.

Is this proper error handling?

On Error Resume Next
Kill (strPCNlockFile)

The error would happen if for some reason the file doesn't exist.
0 Likes
296 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Hi Hutch,

It depends on how you need to handle other errors.

See the posts above for a Fileexists method which you could use to ensure
you don't create an error from the Kill function.

Or you could add an additional line to the code:

On Error Resume Next
Kill (strPCNlockFile)
On Error Goto ErrorHandler

or

On Error Goto 0

etc.

--

Laurie Comerford
CADApps
www.cadapps.com.au
www.civil3Dtools.com
wrote in message news:5450896@discussion.autodesk.com...
In my application a particular file is deleted with a click event of a check
box.

Is this proper error handling?

On Error Resume Next
Kill (strPCNlockFile)

The error would happen if for some reason the file doesn't exist.
0 Likes
Message 3 of 3

Anonymous
Not applicable
Why not test for the file before using the kill statement? ie:

if dir$(strPCNlockFile) <> "" then
Kill (strPCNlockFile)
else
msgbox "File doesn't exist"
end if

In general I think you should try to test for all potential problems you can
think of, and then a generic error handler for everything you don't think of
:-)

something like:

Sub Test()

On Error Goto Error:

if dir$(strPCNlockFile) <> "" then
Kill (strPCNlockFile)
else
msgbox "File " & strPCNlockFile & " doesn't exist"
end if

Exit Sub

Error:

msgbox "Error " & Err.Number & " (Err.Description) & " occured."

End Sub


wrote in message news:5450896@discussion.autodesk.com...
In my application a particular file is deleted with a click event of a check
box.

Is this proper error handling?

On Error Resume Next
Kill (strPCNlockFile)

The error would happen if for some reason the file doesn't exist.
0 Likes