------------------------------------------------------------------------------
| 313 | |
| 314 | //------------------------------------------------------------------------------ |
| 315 | bool vtkMatplotlibMathTextUtilities::CheckForError() |
| 316 | { |
| 317 | vtkPythonScopeGilEnsurer gilEnsurer; |
| 318 | PyObject* exception = PyErr_Occurred(); |
| 319 | if (exception) |
| 320 | { |
| 321 | if (this->Debug) |
| 322 | { |
| 323 | // Fetch the exception info. Note that value and traceback may still be |
| 324 | // nullptr after the call to PyErr_Fetch(). |
| 325 | PyObject* type = nullptr; |
| 326 | PyObject* value = nullptr; |
| 327 | PyObject* traceback = nullptr; |
| 328 | PyErr_Fetch(&type, &value, &traceback); |
| 329 | vtkSmartPyObject tracebackStr; |
| 330 | if (traceback) |
| 331 | { |
| 332 | vtkSmartPyObject tb_module = PyImport_ImportModule("traceback"); |
| 333 | if (tb_module) |
| 334 | { |
| 335 | vtkSmartPyObject format_tb = PyObject_GetAttrString(tb_module, "format_tb"); |
| 336 | if (format_tb) |
| 337 | { |
| 338 | vtkSmartPyObject tracebacklist = |
| 339 | PyObject_CallFunction(format_tb, const_cast<char*>("O"), traceback); |
| 340 | Py_ssize_t tbsz = PySequence_Length(tracebacklist); |
| 341 | tracebackStr = PyUnicode_FromString(""); |
| 342 | for (Py_ssize_t i = 0; i < tbsz; ++i) |
| 343 | { |
| 344 | vtkSmartPyObject item = PySequence_GetItem(tracebacklist, i); |
| 345 | if (!item) |
| 346 | { |
| 347 | continue; |
| 348 | } |
| 349 | tracebackStr = PyUnicode_Concat(tracebackStr, item); |
| 350 | if (!tracebackStr) |
| 351 | { |
| 352 | break; |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | if (!tracebackStr) |
| 359 | { |
| 360 | tracebackStr = PyObject_Str(traceback); |
| 361 | } |
| 362 | vtkSmartPyObject typeStr(PyObject_Str(type)); |
| 363 | vtkSmartPyObject valueStr(PyObject_Str(value)); |
| 364 | vtkWarningMacro(<< "Python exception raised:\n" |
| 365 | << "\nStack:\n" |
| 366 | << (tracebackStr ? const_cast<char*>(PyUnicode_AsUTF8(tracebackStr)) |
| 367 | : "(none)") |
| 368 | << "\nValue:\n" |
| 369 | << (valueStr ? const_cast<char*>(PyUnicode_AsUTF8(valueStr)) : "(none)") |
| 370 | << "\nType:\n" |
| 371 | << (typeStr ? const_cast<char*>(PyUnicode_AsUTF8(typeStr)) : "(none)")); |
| 372 | } |
no outgoing calls
no test coverage detected