[Insight-users] throwing exception inside constructor

Niels Dekker niels-xtk at xs4all.nl
Wed Oct 17 18:06:27 EDT 2007


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




More information about the Insight-users mailing list