The advent of XML has highlighted the importance of namespaces in the data domain. Namespaces also play an important role in C++, specifically in compartmentalizing code. They’re easy to use and they provide numerous benefits such as readability and improved modularity. C++ provides excellent support for handling exceptions.
Namespace code improves the structure of C++ programs, whereas exception handling improves the associated dynamic behavior. Both are useful additions to your C++ arsenal.
As usual in my articles, the code can be downloaded (see the end of this article for the link). The code consists of two files that illustrate the namespace text:
It also includes one file that illustrates C++ exception handling:
If you’re using Visual C++, feel free to create two Win32 Console applications, drop the first two files into the first workspace and build. Then do the same for the second file (SomeExceptions.cpp). The code supplied should compile and run.