Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Feb 24, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Enumerate Your Errors

To keep a list of available error codes in your components, declare a private enumeration:
Private Enum Errors
	InvalidUserID = vbObjectError + 513
End Enum
Setting the first value sets the seed number for all subsequent items in the list, each one incrementing by one. (Microsoft recommends starting at "512 plus 1" above vbObjectError.)

Now you won't have to remember error numbers throughout your code. Simply raise your errors like this:

Err.Raise Errors.InvalidUserID, "Login", "Invalid UserID"
When you type the enumeration name Errors, VB pops up a list of available choices. Be careful, though, not to add new items in the middle of the list, because the value of all entries below the new item increases by one. This can cause the parent of the object to handle errors incorrectly because the error numbers will be different. You can avoid this by specifying exactly what value you want for each Enum, instead of relying on the default increment.
Gregory Alekel
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date