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 code constants are defined by the EthError enumerator. The following error codes are defined:
EthErrorNone - Success, no error.
EthErrorGeneral - A miscellaneous or uncategorized error has occurred.
EthErrorClosing - Function aborted because the device is being closed.
EthErrorNetwork - Network communications error. Connection was unable to be established or existing connection was broken.
EthErrorThread - Internal error occurred in the threads and synchronization library.
EthErrorNotSupported - Function not supported by this device.
EthErrorPipe - Internal API error dealing with data pipes.
EthErrorRthread - Internal API error dealing with the "Reader thread."
EthErrorEthread - Internal API error dealing with the "Event thread."
EthErrorMalloc - Error dynamically allocating memory.
EthErrorWindows - Internal API error specific to the Microsoft Windows platform.
EthErrorWinsock - Internal API error in dealing with the Microsoft Winsock library.
EthErrorNetworkIntr - Network read/write operation was interrupted.
EthErrorWrongMode - Something is not configured correctly in order to allow this functionality.
EthErrorInvalidHandle - Invalid device handle was given.
EthErrorInvalidPort - The given port number does not exist on this device.
EthErrorInvalidBit - The given bit number does not exist on this port.
EthErrorInvalidChannel - The given channel number does not exist on this device.
EthErrorInvalidPointer - The pointer passed in to an API function was invalid.
EthErrorInvalidOther - One of the parameters passed in to an API function was invalid.
EthErrorInvalidValue - The given value is out of range for this I/O port, counter, etc.
EthErrorTimeout - Operation timed out before it could be completed.
EthErrorAlreadyConnected - An object that is already connected cannot have Connect called again.
EthErrorNotConnected - This operation requires the object to be connected.