[Insight-users] throwing exception inside constructor

Hauke Heibel heibel at cs.tum.edu
Thu Oct 18 01:59:39 EDT 2007


Hi Nils,

Oh great, thanks for pointing this out. I have 3.2 and the CVS snapshot on
my computer. Actually I was looking at 3.2's source - well and my compiler
too. The fix that has been made is really nice.

So then Ziv probably/hopefully also uses an old version.

Regards,
Hauke

-----Original Message-----
From: insight-users-bounces+heibel=cs.tum.edu at itk.org
[mailto:insight-users-bounces+heibel=cs.tum.edu at itk.org] On Behalf Of Niels
Dekker
Sent: Thursday, October 18, 2007 12:06 AM
To: insight-users at itk.org
Subject: Re: [Insight-users] throwing exception inside constructor

Hauke Heibel wrote:
> Hi Luis,
> I think your post from before was absolutely ok. The link you provided
> http://nedbatchelder.com/blog/20041202T070735.html
> describes exactly the same issue that arose in Ziv's case and when
> you come to their fix... well, they tried to prevent exceptions
> within the constructor. The problem is that if the constructor of any
> LightObject derived object throws, m_ReferenceCount will always be
> bigger than zero and such the itkExceptionMacro (l. 190,
> itkLightObject.cxx) will be triggered.

Which version of ITK are you refering to?  ITK 3.2.0 does indeed have a 
call to itkExceptionMacro in the destructor of itk::LightObject (l. 190, 
itkLightObject.cxx):
  itkExceptionMacro(<< "Trying to delete object with non-zero reference 
count.");

Fortunately in ITK 3.4.0, this macro call is commented out.  Instead it 
now says:

// A general exception safety rule is that destructors should
// never throw.  Something is wrong with a program that reaches
// this point anyway.  Also this is the least-derived class so the
// whole object has been destroyed by this point anyway.  Just
// issue a warning.
// itkExceptionMacro(<< "Trying to delete object with non-zero reference 
count.");


HTH (I'm sorry I have to go to sleep now!)

Good night,

  Niels


_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users



More information about the Insight-users mailing list