Home > Language Reference > Classes > Err
Raise Method
Generates a runtime error.
Syntax
Public Sub Raise(Optional ByVal iErr As Integer = 0, Optional ByRef sDesc As String = "")
| Parameter | Description |
| iErr | Error number |
| sDesc | Error description |
Remarks
The Raise method throws a runtime error. Like any other error, errors raised by this method can be handled using Try...Catch... and On Error Goto statements.
The optional iErr parameter indicates the error number to raise. Its value is set to the Number property of the Err object before the error is raised, so that an error handler can determine which error occured by reading this property. Error numbers lies between 1 and 32767, values less than 100 being reserved for predefined error messages.
If this parameter is omitted, neither the Number nor the Description properties are modified. This is typically used to forward an error, as shown below:
Try ' Open a progress dialog box f.Show hbFormModeless+hbFormPopup ' Performs some lengthy operation Foo() ' Close the dialog box Unload f Catch ' An error occured. Close the dialog box ' and re-throw the same error. Unload f Err.Raise End Catch
The optional sDesc parameter contains the textual error description. This value is set to the Description property of the Err object before the error is raised. If this parameter is omitted and the error corresponds to a predefined error, the description for this error is used. If this parameter is omitted and the error number do not correspond to a predefined error, the Description property is set to an empty string.
The following example is a function that carries out a simple integer division. The Raise method is used to raise a predefined error #14 if the divisor is null. Note that the sDesc parameter is omitted, so that the error description is automatically initialized with the predefined message for the error #14.
Public Function Divide(ByVal x as Integer, ByVal y as Integer) As Integer If y = 0 Then Err.Raise 14 Divide = x / y End Sub
The following example raises an error defined by the user. In this case, the sDesc parameter is specified, no predefined error message being available for this error number.
Private Sub Button1_Click() Err.Raise 1253, "User defined error!" End Sub
For more information on error handling, refer to the chapter Runtime Error Handling.
System requirements
| System | Minimal version | Remarks |
| Palm OS | Palm OS 3.0 | - |
| Windows CE | Windows CE 3.0 | - |