#include <stdexcept>
class SomeClass {
class Bad {
bool has_error() const;
public:
~Bad() noexcept(false) {
if (has_error()) {
throw std::logic_error("Something bad");
}
}
}// Assume that this class is provided by a 3rd party and it is not something
// that can be modified by the user.
class Bad {
~Bad() noexcept(false);
};
class SomeClass {
Bad bad_member;
public:
~SomeClass()
try {
// ...
} catch(...) {
// Catch exceptions thrown from noncompliant destructors of
// member objects or base class subobjects.
// NOTE: Flowing off the end of a destructor function-try-block causes
// the caught exception to be implicitly rethrown, but an explicit
// return statement will prevent that from happening.
return;
}
}; |