O'Reilly logo

Navigating C++ and Object-Oriented Design by Gail Anderson, Paul Anderson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

13.4. Resource Management

Many applications acquire and release resources (free store memory, files, etc.) with class objects. How do we prevent resource leaks when exceptions occur? This section explores techniques that help manage resources during exception handling. We'll also discuss strategies for throwing exceptions from constructors and destructors. These techniques will improve the designs of your systems and make them more robust with exceptions.

The auto_ptr Class

Using operator new with classes that throw exceptions requires more discipline than using operator new with classes that don't throw exceptions. Consider instantiating a Dbase object, for instance, that throws DbaseError exceptions (see Listing 13.7 on page 616).

 try { Dbase ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required