Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

11.3 But What If Something Goes Wrong?

The client program above is just what you need when things are going well. In the real world, though, things go wrong. Networks crash, operating systems run out of socket resources, and servers aren't always available. Applications written with the net library use C++ exceptions to handle such problems.


NOTE: The remainder of this section assumes you understand C++ exceptions. If you are unfamiliar with exceptions, you should consult a good C++ manual to understand the topic. Several possibilities are listed in the bibliography.

Here is an improved version of our example program. This one detects problems and prints an error message.

Here is what we added:

//1The guts of the example are now enclosed in a try block. If an exception gets thrown from within the try block, the program exits the scope of the try block and tries to find a suitable catch clause to handle the exception.
//2This catch clause catches all of the net library (and Tools.h++) exceptions that could be thrown from within the try block, since all Rogue Wave exceptions are derived from RWxmsg (see the "Errors" section in your Tools.h++ User's Guide for details).
//3Handles 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 net library might throw.

If you had trouble getting the first example program to run correctly, this example may shed some light on the problem by printing an error message. If you still can't get things running, even with the error message, you may want to ask your local network expert for help.


Previous fileTop of DocumentContentsIndexNext file

©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.