This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]