Err.Raise Method |
Microsoft.VisualBasic.ErrObject
Err.Raise( number, source, description , _ helpfile, helpcontext )
A numeric identifier of the particular error
The name of the object or application responsible for generating the error
A useful description of the error
The fully qualified path of a Microsoft Windows Help file containing help or reference material about the error
The context ID within helpfile
Generates a runtime error
To use the Err.Raise method, you must specify an error number.
If you supply any of the number , source , description , helpfile , and helpcontext arguments when you call the Err.Raise method, they are supplied as values to the Number, Source, Description, HelpFile, and HelpContext properties, respectively. Refer to the entries for the individual properties for full descriptions of and rules for each property.
The number argument is a Long integer that identifies the nature of the error. Visual Basic errors (both Visual Basic-defined and user-defined errors) are in the range 0-65535. The range 0-512 is reserved for system errors; the range 513-65535 is available for user -defined errors. When setting the Number property to your own error code in a class module, you add your error-code number to the vbObjectError constant.
The Err.Raise method replaces the older Error statement, which should not be used in new code.
The Raise method does not reinitialize the Err object prior to assigning the values you pass in as arguments. This can mean that if you Raise an error against an Err object that has not been cleared since the last error, any properties for which you don't specify values will still contain the values from the last error.
As well as using Raise in a runtime scenario, you can put it to good use in the development stages of your program to test the viability of your error-handling routines under various circumstances.
The fact that Err.Number only accepts numbers in the range 0-65536 may appear to be strange at first because the data type of the Error Number parameter in the Raise event is a Long. However, deep in the recesses of the Err object, the error code must be declared as an unsigned integer a data type not supported by VB.
Err.Clear Method