ThrowError Property  
 

Enables or disables error handling by the application.

Syntax

object.ThrowError = { True | False }

Remarks

Error handling for methods can be performed using either return codes or exceptions, depending on the value of this property.

If the ThrowError property is set to False, methods will return a status value indicating success or failure. Applications should check the return value of each method and use the LastError and LastErrorString properties to determine the cause of any error.

If the ThrowError property is set to True, errors occurring within the control will be raised to the host application as ActiveX exceptions. In addition, the OnError event will fire. This allows applications to use language-specific exception handling mechanisms, such as Visual Basic error handling, instead of checking individual return values after each method call.

Even when the ThrowError property is set to True, the LastError and LastErrorString properties will still be updated with information about the most recent error.

If an error occurs while accessing a property value, an exception will be raised regardless of the value of the ThrowError property. However, the OnError event will not be fired for property access errors.

Data Type

Boolean

Example

The following example handles errors by checking the return code of a method:

Dim nError As Long

' The control will not raise an exception when an error occurs
Server1.ThrowError = False

' Start the server
nError = Server1.Start()

' If the method returns an error code, then display a message box
' and exit the subroutine
If nError > 0 Then
    MsgBox Server1.LastErrorString, vbExclamation
    Exit Sub
End If

The following example handles errors by generating an exception:

On Error GoTo Failed

' The control will raise an exception when an error occurs 
Server1.ThrowError = True

' Start the server
Server1.Start
Exit Sub

' If the method fails, code execution will resume at this label
Failed:
MsgBox Err.Description, vbExclamation
Exit Sub

See Also

LastError Property, OnError Event