Err.Raise (method)

Syntax

Err.Raise number [,[source] [,[description] [,[helpfile] [,helpcontext]]]]

Description

Generates a runtime error, setting the specified properties of the Err object.

Comments

The Err.Raise method has the following named parameters:

 

Parameter

Description

 

number

A Long value indicating the error number to be generated. This parameter is required.

Errors predefined by BasicScript are in the range between 0 and 1000.

 

source

An optional String expression specifying the source of the error—i.e., the object or module that generated the error.

If omitted, then BasicScript uses the name of the currently executing script.

 

description

An optional String expression describing the error.

If omitted and number maps to a predefined BasicScript error number, then the corresponding predefined description is used. Otherwise, the error "Application-defined or object-define error" is used.

 

helpfile

An optional String expression specifying the name of the help file containing context-sensitive help for this error.

If omitted and number maps to a predefined BasicScript error number, then the default help file is assumed.

 

helpcontext

An optional Long value specifying the topic within helpfile containing context-sensitive help for this error.

If some arguments are omitted, then the current property values of the Err object are used.

This method can be used in place of the Error statement for generating errors. Using the Err.Raise method gives you the opportunity to set the desired properties of the Err object in one statement.

Example

'The following example uses the Err.Raise method to generate

'a user-defined error.

Sub Main()

  Dim x As Variant

  On Error Goto TRAP

  x = InputBox("Enter a number:")

  If Not IsNumber(x) Then

    Err.Raise 3000,,"Invalid number specified","WIDGET.HLP",30

  End If

  MsgBox x

  Exit Sub

  TRAP:

  MsgBox Err.Description

End Sub

See Also

Error (statement), Error Handling (topic), Err.Clear (method), Err.HelpContext (property), Err.Description (property), Err.HelpFile (property), Err.Number (property), Err.Source (property)

More information

E