Absolute C++ (4th Edition) part 77. KEY BENEFIT: C++ programming concepts and techniques are presented in a straightforward style using understandable language and code. KEY TOPICS: C++ Basics; Flow of Control; Function Basics; Parameters and Overloading; Arrays; Structures and Classes; Constructors; Operator Overloading, Friends, and References; Strings; Pointers and Dynamic Arrays; Separate Compilation and Namespaces; Streams and File I/O; Recursion; Inheritance; Polymorphism and Virtual Functions; Templates; Linked Data Structures; Exception Handling; Standard Template Library; Patterns and UML. MARKET: Useful for both beginning and intermediate C++ programmers. . | Exception Handling Basics 767 Syntax try Some_Statements Either some code with a throw statement or a function invocation that might throw an exception Some_More_Statements catch Type e Code to be performed if a value of the catch-block parameter type is thrown in the try block Example See Display for an example. Self-Test Exercises 1. What output is produced by the following code int waitTime 46 try cout Try block entered. n if waitTime 30 throw waitTime cout Leaving try block. n catch int thrownValue cout Exception thrown with n waitTime equal to thrownValue endl cout After catch block endl 2. What would be the output produced by the code in Self-Test Exercise 1 if we made the following change Change the line int waitTime 46 to int waitTime 12 768 Exception Handling 3. In the code given in Self-Test Exercise 1 what is the throw statement 4. What happens when a throw statement is executed Tell what happens in general not simply what happens in the code in Self-Test Exercise 1 or some other sample code. 5. In the code given in Self-Test Exercise 1 what is the try block 6. In the code given in Self-Test Exercise 1 what is the catch block 7. In the code given in Self-Test Exercise 1 what is the catch-block parameter DEFINING YOUR OWN EXCEPTION CLASSES A throw statement can throw a value of any type. A common thing to do is to define a class whose objects can carry the precise kinds of information you want thrown to the catch block. An even more important reason for defining a specialized exception class is so that you can have a different type to identify each possible kind of exceptional situation. An exception class is just a class. What makes it an exception class is how it is used. Still it pays to take some care in choosing an exception class s name and other details. Display contains an example of a program with a programmer-defined exception class. This is just a toy program to illustrate some C details about exception handling. It uses much too much