Rif: Re: C++ Problems

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Rif: Re: C++ Problems

andrea.odetti-2

>At 12:14 PM 4/10/03 +0200, [hidden email] wrote:
>>Hi guys,

>>I'm having strange problems and I would like to have your opinion:
>
>>is there something wrong in throwing an Exception in a constructor?

>Hmm, not that I know of. A rapid Google search brought out
>http://www.gotw.ca/publications/mill13.htm
>for more depth.

thanks, i'll take a look...

andrea

Reply | Threaded
Open this post in threaded view
|

Re: Rif: Re: C++ Problems

Michele Ravani-2
If I remember my C++ (it was years ago, therefore stupidity warning
applies for the following) throwing exceptions in a ctor is (or was)
considered problematic. I can't remember if the application behaviour is
undefined or at least compiler dependent if the constructor doesn't finish.
 
In any case, Stroustrup (third, p.367) mentions that C++ won't call the
dtor of an object which isn't completely constructed, so that you may land
with a leak, depending on how your ctor is implemented.

Having the ctor calling an initialization method is considered safer.

I hope my memory didn't fail me.

--
Michele Ravani                  [hidden email]
"Those who live hoping, die singing" My Gran