Function Try Blocks In constructor
suggest changeA function try block is the only way to catch an exception from a constructor’s initializer list. In the handler, every base and member that was constructed has already been destroyed, so the handler must not use those objects:
struct A : public B
{
A() try : B(), foo(1), bar(2)
{
// constructor body
}
catch (...)
{
// exceptions from the initializer list and constructor are caught here
// if no exception is thrown here
// then the caught exception is re-thrown.
}
private:
Foo foo;
Bar bar;
};
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents