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:

FtpClient1.ThrowError = False
nError = FtpClient1.Connect(strHostName)

If nError > 0 Then
    MsgBox FtpClient1.LastErrorString, vbExclamation
    Exit Sub
End If

The following example handles errors by throwing them to the container:

On Error Resume Next: Err.Clear

FtpClient1.ThrowError = True
FtpClient1.Connect strHostName

If Err.Number <> 0
    MsgBox Err.Description, vbExclamation
    Exit Sub
End If
On Error GoTo 0

See Also

LastError Property, LastErrorString Property, OnError Event