[vtk-developers] C++ exception handling in vtkWrapPython.c

Charl P. Botha cpbotha at gmail.com
Mon Jul 31 18:51:24 EDT 2006


Dear developers,

Today I spent an hour or two working on a patch for vtkWrapPython.c to
add try ... catch exception handling around each call to a C++ class
method.  Afterwards, I discovered that I'd already done this in 2004
[1].  Oi.  The patch I have now is identical except for the #include
<vtkstd/stdexcept> I have now instead of the old #include <exception>.

[1] http://public.kitware.com/pipermail/vtk-developers/2004-March/002806.html

In anycase, the reason why I want to do this is to facilitate error
handling in Python, probably in the same vein as for the relatively
recent vtkWrapTcl.c / Slicer try ... catch patches.  The major problem
with VTK is that if a class early in a pipeline runs into some error,
the whole pipeline continues executing if one does not explicitly
check for problems everywhere.  With a patch such as this, one would
be able to use exceptions for error handling in Python by having a C++
ErrorEvent handler that throws an exception or by adapting
vtkErrorMacro to throw an exception.  One could also abuse this
functionality by creating a new vtkOutputWindow that raises an
exception instead of just outputting the error.

I have two questions:
1. What are the current thoughts on this and other forms of improved
global error handling?
2. Is it okay if I disable those pesky "warning C4702: unreachable
code" errors in VS.NET 7.1 that I get for many of my catch {} clauses?
 The compiler seems to think that it always knows which functions
could implicitly raise exceptions and which couldn't.

Thanks for any thoughts,
Charl



More information about the vtk-developers mailing list