It is dangerous, as you have noticed, to let C++ exceptions propagate
through the Python call stack, including Cython code. Instead, you
should throw Python exceptions, and declare all your C++ library
functions (presumably in a cdef extern block in a pxd file) as except+
to translate them into Python exceptions at this boundary. It's not
safe to try to throw C++ exceptions from a Cython method.
If your C++ code is taking a Cython function as a callback and expects
*it* to throw exceptions, create a wrapper that catches a Python
exception and raises the appropriate C++ exception for your library to
handle. (See the Python/C API for how to do this, and also if there's
an "except return_value" that can be used to detect whether an
exception was raised.) This should be pretty rare.
- Robert