First page Back Continue Last page Graphics
13.9 Constructors, Destructors and Exception Handling
Error in constructor
- new fails; cannot allocate memory
- Cannot return a value - how to inform user?
- Hope user examines object, notices errors
- Set some global variable
- Good alternative: throw an exception
- Destructors automatically called for member objects
- Called for automatic variables in try block
Can catch exceptions in destructor