|
From: Kris T. <kri...@gm...> - 2012-10-13 16:12:23
|
> From: michael kapelko Sent: 13 October 2012 16:04 > I can't make Python print correct C++ exception that I throw (with > exception.what() message). > Here's the example: > https://dl.dropbox.com/u/12634473/swig_py_exception.tar.bz2 > > Building: > > [kornerr@korenmain swig_py_exception]$ make > swig -includeall -python -c++ foo.i > Exception.h:11: Warning 401: Nothing known about base class > 'std::exception'. Ignored. > Exception.h:31: Warning 473: Returning a pointer or reference in a > director method is not recommended. > g++ -fPIC -shared -o _foo.so foo_wrap.cxx -I/usr/include/python2.7 > I haven't downloaded your source, but did you %include "exception.i" at the start of the .i file? I followed the swig user's guide more or less verbatim to catch all exceptions, and it just works %module stir %{ // blab la %} # catch all C++ exceptions in python %include "exception.i" %exception { try { $action } catch (const std::exception& e) { SWIG_exception(SWIG_RuntimeError, e.what()); } catch (const std::string& e) { SWIG_exception(SWIG_RuntimeError, e.c_str()); } } // etc Kris |