Error Handling in C++

The return value of methods and GetLastError() provide information on errors in C++ editions

Date Entered: 05/18/2017    Last Updated: 05/18/2017

In C++ editions of /n software libraries, all class methods return an integer value that indicates whether or not the method call succeeded. If a method completes without error, the return value will be 0. All other return codes indicate an error has occured, in which case GetLastError() will contain more information.

Here is a simple example of common error-handling logic in C++: int ret_code; ret_code = http1.Get(hostName); if (ret_code) { printf("Error: %s\n", http1.GetLastError()); }

The above example uses the HTTP class from IPWorks, but all C++ components support the same flow.

Note: The 'getter' and 'setter' methods for class properties do not follow the above convention.

We appreciate your feedback.  If you have any questions, comments, or suggestions about this entry please contact our support team at kb@nsoftware.com.