O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Error Constants

To raise our own errors using the Err.Raise method, we need error numbers that do not conflict with those used by Visual Basic. The Visual Basic documentation says that error numbers in the range vbObjectError to vbObjectError + 65535, where vbObjectError is a built-in constant whose value is the signed integer -2147220991 (or &H80040000 as an unsigned hexadecimal integer), are designed to signal an error generated by an object.

It further says that error numbers below vbObjectError + 512 may conflict with values reserved for OLE, so these numbers are verboten. Thus, we are left with numbers in the range vbObjectError + 512 to vbObjectError + 65535, which should be plenty.

Many programmers like to assign symbolic constants to error numbers, since it tends to improve readability and cut down on the need for comments. For instance, we could add the line:

Public Const ErrBadDataCt = vbObjectError + 1024

in a standard module.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required