Dealing with the New Exception
Handling this new exception requires a new function in the ErrorHandlingModule's SAMSErrorHandling namespace.
This function, shown in Listing 11.3, is pretty simple.
Listing 11.3. HandleRuntimeError() in ErrorHandlingModule
1: int HandleRuntimeError(runtime_error theRuntimeError) 2: { 3: cerr << 4: theRuntimeError.what() << 5: endl; 6: 7: return 1; 8: } |
Line 1 is the function header and shows the formal argument theRuntimeError, which is of type runtime_error. Line 4 uses the standard exception what() function to get the error message you put into the exception object in lines 14 and 15 of Accumulate(). Line ... |
Get SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION 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.