Error Handling

Errors that may occur within the class or core API cause errors to be raised in your application. This means that as you use the device, you do not need to check return values for error codes. Instead, if an error occurs, an error will be raised and the applicable error handling code you have designated (if any) will be executed. As a rule, you should include error handling code for your application so that, for example, if an attempt to connect to the device fails, it does not cause an unhandled exception (which causes the application to exit).

You should use the "On Error GoTo" statements to install error handlers as is done for any other VB 5/6 error handling. When an error occurs and your error handling code executes, if the error was raised by the Eth32 class, the Err.Number variable will contain one of the possible error codes defined by the EthError enumerator. The following example illustrates the basic idea.

Dim WithEvents dev As Eth32

Private Function MyConnect() As Boolean
	' If we connect successfully, return True.
	' Otherwise, display an error message box and return False otherwise
    On Error GoTo err_handler
    
    Set dev = New Eth32
    
    dev.Connect "192.168.1.100"
    
    MyConnect=True
    Exit Function
err_handler:
    MsgBox "Error connecting to the ETH32 device: " & dev.ErrorString(Err.Number)
    MyConnect=False
	
End Function

Error Codes

Error code constants are defined by the EthError enumerator. The following error codes are defined: