https://stackoverflow.com › questions › 52468416
python - Who should call PyErr_Fetch? - Stack OverflowPy_DECREF is intended to be safe to call with an exception set. If the code inside Py_DECREF needs to do something that isn't safe to do with an exception set, it will take responsibility for saving and restoring the exception state.
https://stackoverflow.com › questions › 1001216
Python C API: how to get string representation of exception?I think that Python exceptions are printed by running "str()" on the exception instance, which will return the formatted string you're interested in. You can get this from C by calling the PyObject_Str() method described here:
https://docs.python.org › 3 › c-api › exceptions.html
Exception Handling — Python 3.12.6 documentationSet the active exception, as known from sys.exception(). This refers to an exception that was already caught , not to an exception that was freshly raised. To clear the exception state, pass NULL .
https://weshallneversurrender.com › PyErr-Fetch
Understanding PyErr_Fetch in Python - WE SHALL NEVER SURRENDERIn the simplest terms, PyErr_Fetch is a function in Python’s C API that retrieves the current active exception. Think about it as a detective fetching clues about what went wrong. It captures the type, value, and traceback of the exception.
https://github.com › python › cpython › issues › 79284
format_exception() doesn't work with PyErr_Fetch #79284 - GitHubWhen embedding Python into a C/C++ based programs, one of the ways to access the formatted traceback is/was to get the type, value and tb by calling the C API PyErr_Fetch() and then call native Python traceback.format_exception() function to get a list of strings representing the tracback.
https://github.com › python › cpython › issues › 102594
Suspected `PyErr_Fetch ()` behavior change · Issue #102594 - GitHubBug report. While testing pybind11 with Python 3.12alpha6 I ran into what looks like a PyErr_Fetch() behavior change. I also tried with the main branch @ c6858d1. I think the issue reduces to: PyErr_SetObject() as e.g. here: https://github.com/pybind/pybind11/blob/442261da585536521ff459b1457b2904895f23b4/tests/test_exceptions.cpp#L309.
https://stackoverflow.com › questions › 1418015
c++ - How to get Python exception text - Stack OverflowIn the Python C API, PyObject_Str returns a new reference to a Python string object with the string form of the Python object you're passing as the argument -- just like str(o) in Python code.
https://github.com › python › cpython › issues › 102192
Replace Fetch/Restore etc by the new exception APIs #102192 - GitHubPyErr_Fetch/Restore etc are now legacy APIs, in some places we can replace them by more efficient alternatives. Linked PRs gh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives (in Python/) #102193
https://sceweb.sce.uhcl.edu › ... › documentation › python_tutorial › api › exceptionHandling.html
4 . Exception Handling - University of Houston–Clear Lakevoid PyErr_Fetch (PyObject **ptype, PyObject **pvalue, PyObject **ptraceback) Retrieve the error indicator into three variables whose addresses are passed. If the error indicator is not set, set all three variables to NULL. If it is set, it will be cleared and you own a reference to each object retrieved.
https://peps.python.org › pep-0490
PEP 490 – Chain exceptions at C level | peps.python.orgModify PyErr_* () functions to chain exceptions. Modify C functions raising exceptions of the Python C API to automatically chain exceptions: modify PyErr_SetString(), PyErr_Format(), PyErr_SetNone(), etc. Modify functions to not chain exceptions.