13.8. Putting It All Together

A RintError Exception Hierarchy

In Section 7.4 on page 329, we introduced a range integer class (Rint) with overloaded operators. Recall that range integers are built with an initial value, a minimum, and a maximum.

Rint i(5, 1, 10);            // value=5, min=1, max=10 
i = 8;                       // OK
i = 88;                      // error

An overloaded assignment operator verifies that a range integer maintains its value within a specified range. Likewise, a constructor verifies that Rint objects have been built properly.

Rint j(5, 10, 1);            // error, max > min 
Rint k(55, 1, 10);           // error, initial value not within range

Error handling with Rint is minimal, using one exception class to handle all possible errors (see Listing 7.6 on page 331). An exception hierarchy ...

Get Navigating C++ and Object-Oriented Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.