The core function `PyErr_Occurred()` checks if an exception is pending, returning a borrowed reference to the exception type or `NULL`. For retrieving and temporarily clearing the full exception state (type, value, traceback) for advanced handling, `PyErr_Fetch()` is used. [1, 3, 4, 8, 10]