SocketTools .NET Edition

DnsClient.ThrowError Property

Enable or disable exceptions being raised when a method fails.

[Visual Basic]
Public Property ThrowError As Boolean
[C#]
public bool ThrowError {get; set;}

Remarks

Error handling for method calls can be done in either of two different styles, according to the value of this property.

If the ThrowError property is set to false, the application should check the return value of any method that is used, and report errors based upon the documented value of the LastError property. It is the responsibility of the application to interpret the error code and act accordingly.

If the ThrowError property is set to true, then errors that occur when calling a method will cause an exception to be raised. The application must handle the exception using the error handling facilities in the language being used. For example, in Visual Basic, the Try..Catch..End Try statements can be used.

Note that if an error occurs while a property is being read or written, an exception will always be raised regardless of the value of this property.

Example

The following examples demonstrate the difference between handling errors when calling the Resolve method. In the first example, the ThrowError property is set to False, which means that the Resolve method will return True or False, depending on whether it succeeds or fails. If it returns False, the LastError and LastErrorString properties can be used to determine the error.

In the second example, the ThrowError property is set to True, which causes the Resolve method to throw an exception if an error occurs. This is handled by the Try..Catch..End Try block, and the DnsClientException class provides information about the error.

[Visual Basic]
dnsClient.ThrowError = False
 
If dnsClient.Resolve(strHostName, strHostAddress) = False Then
    MsgBox(dnsClient.LastErrorString, MsgBoxStyle.Exclamation)
    Exit Sub
End If
    
[Visual Basic]
dnsClient.ThrowError = True
 
Try
    dnsClient.Resolve(strHostName, strHostAddress)
Catch ex As SocketTools.DnsClientException
    MsgBox(ex.Message, MsgBoxStyle.Exclamation)
End Try
    

See Also

DnsClient Class | SocketTools Namespace | DnsClientException Class | LastError Property | LastErrorString Property