Purpose
Controls error handling. You can use this command to prevent runtime errors from stopping the program.
Syntax
On Error Goto Label
On Error Resume
On Error Resume Next
On Error Goto 0
This command is used with the following commands:
Goto Label |
Processing jumps to the line that starts with the label if a critical error occurs. The label can be either a line number (consisting of the numbers 0-9) or an alphanumeric string (as long as it does not start with a number). The label must be the first nonblank characters on the line followed by a colon (:). |
Resume |
The application will try to re-execute the line that caused the error until it executes successfully. Be careful about using this command, because the application could loop on this line indefinitely. |
Resume Next |
Processing resumes with the line after the line that caused the error, including critical errors. Any lines that cause errors are skipped, and processing doesn't stop for critical errors. |
Goto 0 |
Turns off error handling from this point on. |
Example
Sub Main()
Dim i As Integer
On Error Goto ErrHandler
i=1/0 'division by zero error
Print "Error handling has resumed execution here"
Exit Sub
|