This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: g++: Exception handling in constructor
On Wed, Dec 11, 2002 at 09:41:21AM -0000, Rob Shearer wrote:
>
> >From the standard:
> 15.3.16: "The exception being handled is rethrown if control reaches the
> end of ahandler of the function-try-block of a constructor or
> destructor."
>
> I don't really see any other choice: the object couldn't be constructed,
> so you can't just return from the constructor and silently leave the
> caller with uninitialize memory.
Thanks for your answer.
I don't see the point that the exceptions is re-thrown _automatically_
when it _is_ caught by the constructor...
Because when the exception gets caught by the constructor
function-try-block, the object can be set to a more-or-less "proper" state
and knows that initialization went wrong, and _maybe_ an exception is
thrown to the caller to signal a problem, but the caller could also
check the state later with another function (maybe bool operator!() const).
--
Frank Grimm // fgr@foobar-cpa.de
// www.foobar-cpa.de