| 18 | namespace { |
| 19 | |
| 20 | std::string getPythonExceptionInfo() |
| 21 | { |
| 22 | if (!PyErr_Occurred()) { |
| 23 | return "no Python exception raised"; |
| 24 | } |
| 25 | |
| 26 | PyObject* ex_type; |
| 27 | PyObject* ex_value; |
| 28 | PyObject* traceback; |
| 29 | PyErr_Fetch(&ex_type, &ex_value, &traceback); |
| 30 | PyErr_NormalizeException(&ex_type, &ex_value, &traceback); |
| 31 | if (traceback == nullptr) { |
| 32 | traceback = Py_None; |
| 33 | } |
| 34 | char* c_exstr = ct_getExceptionString(ex_type, ex_value, traceback); |
| 35 | string message; |
| 36 | if (c_exstr != nullptr) { |
| 37 | message = c_exstr; |
| 38 | free(c_exstr); |
| 39 | } else { |
| 40 | message = "Couldn't get exception message"; |
| 41 | } |
| 42 | Py_XDECREF(ex_type); |
| 43 | Py_XDECREF(ex_value); |
| 44 | Py_XDECREF(traceback); |
| 45 | return message; |
| 46 | } |
| 47 | |
| 48 | } // end anonymous namespace |
| 49 |
no outgoing calls
no test coverage detected