...
Code Block |
---|
struct Foo {
Foo(); // may throw
~Foo(); // may throw
};
Foo A;
void bar() {
static Foo B;
}
int main()
try {
bar();
// other executable statements
}
catch(...) {
// will catch exceptions thrown from bar() and
// any other executable statements in the try
// block above
// IMPORTANT: will not catch exceptions thrown
// from the constructor of the global object A
// or those from the destructor of the static
// local object B defined in bar()
}
|
Thus, it is important to prevent constructors and destructors of objects with static storage duration to throw exceptions. See also ERR33-CPP. Destructors must not throw exceptions.