Chapter 3

Constructors, Destructors, and Exceptions

IN THIS CHAPTER

check Writing and using different kinds of constructors

check Writing destructors

check Understanding constructor and destructor ordering

check Throwing and catching exceptions

In this chapter, you encounter three vital topics: constructors, destructors, and exceptions. Fully understanding what goes on with constructors (creating an object) and destructors (destroying an object) is very important. The better you understand how constructors and destructors work, the less likely you are to write class and structure code that doesn’t function the way you expected and the more likely you are to avoid bugs.

Exceptions are important also in that they let you handle unexpected situations — that is, you can handle problems when they do come up. An exception can signal a program error, a missing resource, use input issues, or any number of other situations that the application code didn’t expect. That’s why it’s called an exception — an exception to what was expected.

Many developers feel that constructors, destructors, and exceptions are extremely ...

Get C++ All-in-One For Dummies, 4th 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.