Exceptions and design

Reporting errors with exceptions and cleaning up during stack unwinding, then putting the whole course together in the design of a complete small program.

About 7 hours of study

Learning objectives

Lessons

  1. 1

    Exceptions

    throw reports an error, try and catch handle it far away, and destructors still run on the way: safe error handling in C++.

  2. 2

    Project: a small library system

    Putting it together: classes with private data, inheritance and virtual functions, a vector of pointers, and exceptions for errors.

Module practice

Module quiz

1. What runs after a throw inside a function?
2. How should an exception usually be caught?
3. Does catch (const exception& e) catch a runtime_error?
4. What happens to local objects in the functions an exception leaves?
5. A catch for exception comes before a catch for out_of_range. What happens when out_of_range is thrown?
6. In the library design, why are the Library's copy constructor and assignment deleted?
7. In object-oriented design, the nouns of a problem description usually suggest what?

‹ Templates and the standard libraryFinal assessment ›