Most of the SmartSockets functions return FALSE
on failure, and TRUE
on success. The corresponding C++ member functions throw exceptions on failure. Each class in the C++ library has an associated exception class.
A block written in C looks similar to this:
if (!TipcMsgAppendStr(msg, "voltage")) { TutOut("Could not append first field.\n"); return T_EXIT_FAILURE; }
In C++, this same code looks similar to this:
try { msg << "voltage"; } catch (TipcMsgException msge) { TutOut("Could not append first field.\n"); return T_EXIT_FAILURE; }
In the next example, TipcMsg::getDest calls the C function TipcMsgGetDest. If the C API returns FALSE
, then a TipcMsgException exception is thrown to the user:
/* =============================================================== */
/*..TipcMsg::dest -- get the destination property of a message */
const char * TipcMsg::getDest() const throw (TipcMsgException) { char * dest_return = (char *)"";// initialize variable
if (!TipcMsgGetDest(_msg, &dest_return)) throw TipcMsgException(); return const_cast<const char*> (dest_return); }
Use the try
/catch
block to handle unexpected behavior from the member function:
try { TipcMsg msg; char* the_dest = (char *)msg.getDest(); } catch (TipcMsgException msge) { // handle the error }
Each main class in the C++ library has an associated Exception class. The exception hierarchy follows the main classes in the class hierarchy. For example, exceptions generated from methods in the TipcMt class throw TipcMtException exceptions. Figure 1 shows the Exception class hierarchy.
Each Exception class includes these member functions, which retrieve information about errors that are generated:
For more information on all error codes, see the TIBCO SmartSockets API Quick Reference.
TIBCO SmartSockets™ C++ User’s Guide Software Release 6.8, July 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |