All of this I found in the Basic Programmer's Guide
I've never actually done it but it should go something
like this:
Sub Test
On Error Goto ErrorHandler
' ... undertake task during which an error may occur
Exit Sub
ErrorHandler:
' ... individual code for error handling
End Sub
or
The Resume Command
The Resume Next command continues the program from the
line that follows where the error
occurred in the program after the code in the error
handler has been executed:
ErrorHandler:
' ... individual code for error handling
Resume Next
Use the Resume Proceed command to specify a jump point
for continuing the program after error
handling:
ErrorHandler:
' ... individual code for error handling
Resume Proceed
Proceed:
' ... the program continues here after the error
To continue a program without an error message when an
error occurs, use the following format:
Sub Test
On Error Resume Next
' ... perform task during which an error may occur
End Sub
#####################
Tips for Structured Error Handling
Both the definition command, On Error, and the return
command, Resume, are variants of the
Goto construct.
If you want to cleanly structure your code to prevent
generating errors when you use this
construct, you should not use jump commands without
monitoring them.
Care should be taken when you use the On Error Resume
Next command as this dismisses all
open error messages.
The best solution is to use only one approach for
error handling within a program - keep error
handling separate from the actual program code and do
not jump back to the original code after
the error occurs.
The following is an example of an error handling
procedure:
Sub Example
' Define error handler at the start of the function
On Error Goto ErrorHandler
' ... Here is the actual program code
' Deactivate error handling
On Error Goto 0
' End of regular program implementation
Exit Sub
' Start point of error handling
ErrorHandler:
' Check whether error was expected
If Err = ExpectedErrorNo Then
' ... Process error
Else
' ... Warning of unexpected error
End If
On Error Goto 0 ' Deactivate error handling
End Sub
This procedure begins with the definition of an error
handler, followed by the actual program
code. At the end of the program code, the error
handling is deactivated by the On Error Goto 0
call and the procedure implementation is ended by the
Exit Sub command (not to be confused
with End Sub).
The example first checks if the error number
corresponds to the expected number (as stored in the
imaginary ExpectedErrorNo constant) and then handles
the error accordingly. If another error
occurs, the system outputs a warning. It is important
to check the error number so that
unanticipated errors can be detected.
The On Error Goto 0 call at the end of the code resets
the status information of the error (the
error code in the Err system variables) so that an
error occurring at a later date can however be
clearly recognized.
hope this helps.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]