Re: is such exception handling approach good?




"Ben Voigt [C++ MVP]" <rbv@xxxxxxxxxxxxx> wrote in message
news:egI8BxlRIHA.748@xxxxxxxxxxxxxxxxxxxxxxx

"ajk" <ak@xxxxxxxxxxxx> wrote in message
news:c2cpm39cglur8b0oajuveaf4mv9hoicdcb@xxxxxxxxxx
On Fri, 21 Dec 2007 10:46:40 -0500, "Larry Smith"
<no_spam@xxxxxxxxxxx> wrote:

it is normally not a good idea to do operations in the ctor that could
cause an exception. the reason for this is that if an exception is
ever thrown in your ctor you end up with an invalid object. therefore
it is better to have some other method to initialize such with and
handle a failure outside the ctor like bool init() or something.

That's completely false as Alex stated.


i forgot to add: the dtor is never called when ctor throws an
exception so the heck do you do the cleanup if the ctor has allocated
three different things?

constructor function-try block

Sorry, it can't refer to members http://www.gotw.ca/gotw/066.htm

The member have to clean themselves up by defining appropriate destructors.



please tell me since you obviously have such insight.




.