Defining Your Own Error Values

The preceding section explains how you can use run-time error values to diagnose problems in your code and respond appropriately to the problems. There may be times, however, when you want to detect and respond to situations that don't cause Visual Basic to generate errors. To do this, you need to create your own user-defined error values for those situations.

This type of error value is commonly used in procedures that accept several arguments and then return a value. Suppose the return value is valid only if the arguments fall within certain ranges. Your procedure can test the arguments that the user provides; if they aren't in the acceptable range, you can have the procedure return an appropriate error value.

The following sections describe how to create a user-defined error value using the CVErr function and how to test for an error value using the IsError function.