Overview
Chapter 14 covers the topic of exceptions. After being introduced to exceptions, students
explore various techniques of dealing with exceptions. In particular, the C++
try/catch block and C++ exception classes will be examined. Students will also
learn how to create their own exception classes and throw exceptions. Finally, the
process of stack unwinding as it relates to exceptions will be explained.
Objectives
In this chapter, the student will:
• Learn what an exception is
• Learn how to handle exceptions within a program
• Learn how a try/catch block is used to handle exceptions
• Learn how to throw an exception
• Become familiar with C++ exception classes and how to use them in a program
• Learn how to create your own exception classes
• Discover how to throw and rethrow an exception
• Explore exception handling techniques
• Explore stack unwinding
Teaching Tips
Handling Exceptions within a Program
1. Define an exception and give some simple examples, such as division by zero or out of
bounds access to an array.
Your students will be all too familiar with exceptions by this point. They have
most likely encountered numerous exceptions from input errors and out of range
errors while programming and testing. Ask them to share common errors and/or
exceptions they have found in their programs.
2. Review the ways in which students have dealt with exceptions until this point, including
3. Review situations in previous chapters where exceptions were ignored and the program