Handling an Error

There are no special tricks to handling an error. How an error is handled depends on the specifics of your program and the error that occurred. You must know the situation that can cause a specific error, as well as what that error means to your program, and then write error-handling code as appropriate.

Let's look at an example. Suppose your program expects to find a database file located on a network share. There are several things that can go wrong and cause an error:

  • The file is not found (error 53).

  • The path is not found (error 76).

  • The device is unavailable (error 68).

  • There is a path/file access error (error 75).

Depending on which error occurs, you may want to retry the operation, alert the user to contact the network administrator, ...

Get Office® XP Development with VBA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.