This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: g++: Exception handling in constructor
- From: John Love-Jensen <eljay at adobe dot com>
- To: Frank Grimm <fgr at foobar-cpa dot de>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: Wed, 11 Dec 2002 08:13:20 -0600
- Subject: Re: g++: Exception handling in constructor
Hi Frank,
> I don't see the point that the exceptions is re-thrown _automatically_
> when it _is_ caught by the constructor...
The end of the constructor's catch block has a few options:
+ call exit()
+ call some other non-returning function
+ throw it's own exception
+ longjmp() -- not recommended
+ explicit re-throw
+ implicit re-throw (i.e., fall off the end of the catch block)
Remember: the object was NOT constructed. So the catch block cannot
silently consume the exception and pass a pile of bits back which the caller
would assume is a kosher object. That would be deadly.
*IF* you fall off the end of the constructor's catch block -- which is there
to allow an opportunity for cleanup (and logging and debugging) -- *THEN*
the exception *MUST* be propagated.
Or you'd be running with a broken axle.
Sincerely,
--Eljay