Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Whenever your program interacts with the outside world, you should provide some form of error handling to counteract unexpected inputs or outputs. One way of providing error handling is to write your own error-handling routines.
Error-handling routines are the traffic control for your program. Such routines can handle any kind of programming or human-generated errors you can think of. They should not only identify the error, but try to fix it—or at least give the program or interacting human a chance to do so.
To begin error handling in a procedure, use the On Error GoTo statement to signify that you are going to use an error-handling routine:
On Error GoTo ErrorHandler
This statement can go anywhere in your procedure, but should be placed toward the top, generally right after any procedure-level variable declarations.