ErrObject.Raise Method
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Generates a run-time error; can be used instead of the Error statement.
Namespace: Microsoft.VisualBasic
Assembly: Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
Syntax
'Declaration
Public Sub Raise ( _
Number As Integer, _
Description As Object _
)
public void Raise(
int Number,
Object Description
)
Parameters
- Number
Type: System.Int32
Required. Long integer that identifies the nature of the error. Visual Basic 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. For example, to generate the error number 513, assign vbObjectError + 513 to the Number property.
- Description
Type: System.Object
Optional. String expression describing the error. If unspecified, the value in the Number property is examined. If it can be mapped to a Visual Basic run-time error code, the string that would be returned by the Error function is used as the Description property. If there is no Visual Basic error corresponding to the Number property, the "Application-defined or object-defined error" message is used.
Remarks
All of the Raise arguments except Number are optional. If you omit optional arguments, and the property settings of the Err object contain values that have not been cleared, those values serve as the values for your error.
Examples
This example uses the Err object's Raise method to generate an error within a function written in Visual Basic. The calling function can catch the error and report it to the user with a message box.
Const WidthError As Integer = 1
Const WidthHelp As Object = 101
Dim Msg As String
Sub TestWidth(ByVal width As Integer)
If width > 1000 Then
Err.Raise(vbObjectError + 512 + WidthError, "TestWidth")
End If
End Sub
Sub CallingProcedure()
Try
TestWidth(2000)
Catch ex As Exception
Msg = ex.Message
End Try
End Sub
Version Information
Silverlight
Supported in: 5, 4, 3
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
See Also