![]() |
![]() |
| ||||||||||||||||||||
Chapter 14Handling ErrorsThe ToolTalk service returns error status in the function's return value rather than in a global variable. ToolTalk functions return one of these error values:
Each return type is handled differently to determine if an error occurred. For example, the return value for tt_default_session_set is a Tt_status code. If the ToolTalk service sets the default session to the specified sessid:
Retrieving ToolTalk Error StatusYou can use the ToolTalk error handling functions shown in Table 14-1 to retrieve error values. Table 14-1 Retrieving ToolTalk Error Status
The return type for these function is Tt_status. Checking ToolTalk Error StatusYou can use the ToolTalk error macro shown in Table 14-2 to check error values. Table 14-2 ToolTalk Error Macros
Returned Value StatusThe following sections describe the return value status of functions with natural return values and functions with no natural return value. Functions with Natural Return ValuesIf a ToolTalk function has a natural return value such as a pointer or an integer, a special error value is returned instead of the real value. Functions with No Natural Return ValuesIf a ToolTalk function does not have a natural return value, the return value is an element of Tt_status enum. To see if there is an error, use the ToolTalk macro tt_is_err, which returns an integer.
If there is an error, you can use the tt_status_message function to obtain the character string that explains the Tt_status code, as shown in Example 14-1. Example 14-1 Obtaining an Error Explanation
Returned Pointer StatusIf an error occurs during a ToolTalk function that returns a pointer, the ToolTalk service provides an address within the ToolTalk API library that indicates the appropriate Tt_status code. To check whether the pointer is valid, you can use the ToolTalk macro tt_ptr_error. If the pointer is an error value, you can use tt_status_message to get the Tt_status character string. Example 14-2 checks the pointer and retrieves and prints the Tt_status character string if an error value is found. Example 14-2 Retrieving a Returned Pointer Status
Returned Integer StatusIf an error occurs during a ToolTalk function that returns an integer, the return value is out-of-bounds. The tt_int_error function returns a status of TT_OK if the value is not out-of-bounds. To check if a value is out-of-bounds, you can use the tt_is_err macro to determine if an error or a warning occurred. To retrieve the character string for a Tt_status code, you can use tt_status_message. Example 14-3 checks a returned integer. Example 14-3 Checking a Returned Integer
| ||||||||||||||||||||
| ||||||||||||||||||||