[vtk-developers] Exceptions

Ken Martin ken.martin at kitware.com
Mon Mar 22 10:57:00 EST 2004


OK, Since this issue has been raised before let's take a couple minutes to
discuss it. I have heard good and bad things about exceptions but I am not
personally that familiar with them. So I'd like for some folks who have
experience using exceptions in a large project to provide some input. From
what I've seen here are the good and the bad:

(Good) Using exceptions allows for problems to be caught and handled in a
deep stack such as pipeline execution without having to put in a lot of
extra checks. I'm not 100% sure I buy this argument. Since a filter's input
can be a pipeline or just a plain data object I don't see how the required
testing is reduced. For many cases where a pipeline could produce a bad
data/metadata the same bad metadata could be passed to the filter directly
(without a pipeline). But I will agree that it could help.

(Good) Using exceptions allows for effectively testing many functions in one
try block. This I think is a great feature. If anything ran out of memory in
this try block then do this... is a great feature.

(Bad) There is a tendency to believe that throwing an exception makes
everything OK. Exception based error handling seems to frequently lack
appropriate try / catches. For example: some image writers in VTK will write
out a volume as a series of slices. If the writer should run out of disk
space then the error handling will actually go back and delete the slices
already written so that an incomplete volume is not left on the disk. My
concern is that with exceptions most people would just throw the exception
and feel their job was done. I don't think this is a technical problem with
exceptions but rather a bad coding practice where not enough effort is put
into the try catch blocks that are required to make exceptions useful. (the
same problem exists with not checking the return value of malloc etc, so it
isn't limited to exceptions, but I think exceptions exacerbate the problem)

Other comments? Feedback?

Thanks
Ken










More information about the vtk-developers mailing list