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

Charl P. Botha cpbotha at gmail.com
Wed Aug 2 04:15:36 EDT 2006

Dear Brad,

Thanks for the info!

On 8/1/06, Brad King <brad.king at kitware.com> wrote:
> Charl P. Botha wrote:
> > [1]
> > http://public.kitware.com/pipermail/vtk-developers/2004-March/002806.html
> This is already done in vtkWrapTcl.c so you can just port the fix from
> there.  Don't bother with catch(...) at all.  Just catching
> vtkstd::exception should be fine.

The Tcl code differs from the Python code.  As far as I could see, the
Tcl code gets one large function (<filtername>CppCommand()) where all
methods handled in a large conditional.  There is a single try...catch
for every VTK filter.

In Python, there is a separate wrapped function for every method of
the class.  I'll take my old patch and just remove the catch(...)
bits.  The only reason for this patch would be to catch bad_alloc
exceptions, just like for the Tcl code.  Your comments later about
exception safety are of course completely valid and exclude almost all
other (ab)uses of exceptions in VTK code.

> > 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.
> [snip]
> > 1. What are the current thoughts on this and other forms of improved
> > global error handling?
> The VTK 5.0 pipeline does not keep executing.  If one algorithm fails
> the error is reported and the executives do not ask any more algorithms
> to run.

I forgot that this was one of the improvements of your new pipeline,
I've seen it happening quite often.  However, the pipeline stops
because data is not available at some point, or because some
algorithm's ProcessRequest returned false, and not because e.g.
vtkErrorWithObjectMacro is called, right?  Also, as far as I can
remember, there is no central way to query the error information (for
example the error message).

> conventions were established before C++ even had exceptions.  Trying to
> use exceptions to escape from filters on error will probably result in
> resource leaks, which does not even meet the basic exception guarantee.

You're obviously completely right.

I'm going to try some other solution, probably another layer of Python
wrapping around each and every VTK filter that instruments each filter
with an ErrorEvent handler and checks the filter for errors after
every single method call.

Thanks again,

More information about the vtkusers mailing list