Chapter 3
Constructors, Destructors, and Exceptions
IN THIS CHAPTER
Writing and using different kinds of constructors
Writing destructors
Understanding constructor and destructor ordering
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access