Search code examples
pythonc++exceptionembedding

Propagating embedded Python Exceptions up to C++


If I have C++ code with embedded Python functions, i.e. it uses Python's C API to call Python's interpreter, how can I get Python exceptions to bubble up to the C++ level?


Note: This is not the inverse question (about propagating C++ extension exceptions up to the Python intepreter).


Solution

  • https://docs.python.org/2/c-api/exceptions.html

    specifically, PyErr_PrintEx(0) -- this will print a traceback.