Error Handling

Typically an error is indicated when a SocketTools function either returns a value of zero (false) or -1. When an error occurs in one of the libraries, the GetLastError function can be used to obtain the error code. The GetLastError function returns a unsigned 32-bit integer value that is unique to each thread in a given application. Each library also has it's own private function which will return the last error code for the current thread. For example, the File Transfer Protocol library has a function called FtpGetLastError. SocketTools error codes conform to the standard format used by Windows:

Error Handling

The S bitfield is used to refer to the severity of the error. A value of zero specifies success, while a value of one specifies an error condition.

The R bitfield is reserved for future use by Windows, and must be set to zero. Applications should not take any action based on the values of these two bits.

The Facility bitfield specifies which group of status codes the error belongs to. The SocketTools libraries use FACILITY_ITF, which is designated for use by third-party libraries.

The Code bitfield specifies the actual error code. This may correspond to a Windows Sockets error, or an error that is unique to the SocketTools libraries.

Each of the SocketTools error codes has a matching constant, defined in the header files or modules provided for your programming language. These constants should always be used for comparison against the value returned by the GetLastError function.

For each error code, there is a matching description of the error which can be used by the application. Applications may choose to use these error descriptions when displaying a message box to a user or for internal logging purposes. To retrieve the description of the error, the FormatMessage function can be used. Each library also has its own private function to return an error description which may be easier to use. For example, the File Transfer Protocol library has a function called FtpGetErrorString, the Hypertext Transfer Protocol library has a function called HttpGetErrorString and so on.


Copyright © 2008 Catalyst Development Corporation. All rights reserved.