Example 1 does not handle errors. Example 2 is an improved version that detects errors and prints a message.
This section assumes that you understand C++ exceptions.
#include <rw/rstream.h> #include <rw/network/RWSocketPortal.h> #include <rw/network/RWInetAddr.h> #include <rw/network/RWWinSockInfo.h> int main() { RWWinSockInfo info; try { //1 RWSocketPortal p( RWInetAddr(3010,"net.roguewave.com") ); p.sendAtLeast("Hello out there!"); } catch (const RWxmsg& x) { //2 cerr << "Problem! " << x.why() << endl; //3 } return 0; } |
//1 | Encloses the main part of the example in a try block. If an exception is thrown from within the try block, the program exits the scope of the try block and looks for a catch clause to handle the exception. |
//2 | Catches all Networking package and SourcePro Core exceptions that can be thrown from within the try block (all Rogue Wave exceptions are derived from RWxmsg). For more information, see the Essential Tools Module User's Guide. |
//3 | Handles the exception by printing an error message. The member function why() is part of the RWxmsg class interface and is available for any exception that the Networking package might throw. |
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.