Handling Errors
Example 1 does not handle errors.
Example 2 is an improved version that detects errors and prints a message.
NOTE: This section assumes that you understand C++ exceptions.
Example 2 – Handling errors
#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;
}