[Insight-users] Python wrapping + exceptions

Charl P. Botha c . p . botha at ewi . tudelft . nl
18 Jul 2003 16:39:30 +0200


Hi Luis and ITK Python People,

On Wed, 2003-07-16 at 02:44, Luis Ibanez wrote:
> Your observation is correct,
> ITK is throwing a C++ exception that is not being catched.

> The ideal fix would be to figure out a mechanism for catching
> C++ exceptions and translate them into Python exceptions.

This is possible with swig:
http://www . swig . org/Doc1 . 1/HTML/Exceptions . html
and also see SWIG/Examples/python/except*

I've been studying the CableSwig sourcecode, obviously primarily
CableSwig.cxx and specifically CreatSwigMethod.  One would have to set
the "throws" attribute of the Swig method node correctly (I have no idea
how to do this yet) and this would be the beginning of having C++
exceptions translated to Python exceptions.

I could probably spend some time on this, but I have the feeling that
the CableSwig experts would be able to implement this functionality in
far less time.  Any takers?  

If not, some more advice would be greatly appreciated.  The
documentation for SWIG is relative straightforward (i.e. doing it the
normal way with .i interface files and all that) but CableSwig is
obviously doing it differently (via the gccxml-generated XML) and this
is taking time to figure out.

Any help would be greatly appreciated.

Thanks,
Charl

-- 
charl p. botha http://cpbotha . net/ http://visualisation . tudelft . nl/