[Insight-users] Suggestions for itk::ExceptionObject
Niels Dekker
niels-xtk at xs4all.nl
Tue Jul 24 07:05:28 EDT 2007
I just wrote an exception class for our own C++ library at LKEB
(www.lkeb.nl), that is very much inspired by itk::ExceptionObject: It is
derived from std::exception, and it has a description, a source file name, a
line number, and a function name. I also copied your wonderful
itkExceptionMacro(x) macro from itkMacro.h. Basically I very much appreciate
the interface of itk::ExceptionObject, but I think its implementation could
be improved. For instance, the copy constructor of itk::ExceptionObject
might throw an std::bad_alloc. Doing so might cause the program to
terminate immediately.
I highly recommend you to check out the guidelines from "How should I design
my exception classes?", by David Abrahams:
http://www.boost.org/more/error_handling.html Please take a look at
guideline 2, 3, and 4:
2. Use virtual inheritance
3. Don't embed a std::string object
4. Format the what() message on demand
Are there any plans to get itk::ExceptionObject in accordance to those
guidelines?
FYI, For the implementation of our own Lkeb::Exception class, I'm using a
reference counting mechanism, to make sure that its copy constructor never
fails.
Kind regards,
--
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center
More information about the Insight-users
mailing list