helper function so we can capture the currently active C++ exception into a python object.
| 97 | |
| 98 | // helper function so we can capture the currently active C++ exception into a python object. |
| 99 | py::object translate_current_exception() |
| 100 | { |
| 101 | py::object locals = py::dict(); |
| 102 | locals["rethrow_"] = py::cpp_function([]{throw;}); |
| 103 | PyRun_String(R"( |
| 104 | try: |
| 105 | rethrow_(); |
| 106 | result = None |
| 107 | except Exception as e: |
| 108 | result = e; |
| 109 | |
| 110 | )", Py_single_input, PyEval_GetGlobals(), locals.ptr()); |
| 111 | return locals["result"]; |
| 112 | } |
| 113 | |
| 114 | struct py_coroutine |
| 115 | { |