Axiom 2: It's Safe to Destroy
This is a socially based, not technically based, axiom. Conventionally, destructors, operator delete, and operator delete[] do not throw exceptions. Consider an imaginary destructor that must delete two pointer data members. We know that we'll be criticized, ostracized, and marginalized if we allow an exception to propagate from the destructor, so we may be tempted to reach for a try block:
X::~X() {
try {
delete ptr1_;
delete ptr2_;
}
catch( ... ) {}
}
This is not necessary or advisable, since the fear of social ostracism also (one hopes and assumes) affects the authors of the destructors and operator deletes of the objects to which ptr1_ and ptr2_ refer. We can play on those fears to make our task easier:
X::~X() {
delete ptr1_;
delete ptr2_;
}
 |