// void 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. The value and traceback object may be NULL even when the type object is not. // // Note This function is normally only used by code that needs to handle exceptions or by code that needs to save and restore the error indicator temporarily. func PyErr_Fetch() (exc, val, tb *PyObject) { exc = &PyObject{} val = &PyObject{} tb = &PyObject{} C.PyErr_Fetch(&exc.ptr, &val.ptr, &tb.ptr) return }
func exception() error { if C.PyErr_Occurred() == nil { return syscall.EFAULT } var t, v, tb *C.PyObject C.PyErr_Fetch(&t, &v, &tb) return newError(newObject(t), newObject(v), tb) }
func exception() error { if C.PyErr_Occurred() == nil { return nil } var t, v, tb *C.PyObject defer C.xdecref(v) C.PyErr_Fetch(&t, &v, &tb) return &Error{newObject(t), newObject(v), tb} }
// getError translates the current Python exception to a Go error, and clears // the Python exception state. func getError() error { var ( pyType *C.PyObject pyValue *C.PyObject pyTrace *C.PyObject ) C.PyErr_Fetch(&pyType, &pyValue, &pyTrace) defer C.DECREF(pyType) defer C.DECREF(pyValue) defer xDECREF(pyTrace) C.PyErr_Clear() return fmt.Errorf("Python: %s", stringify(pyValue)) }
// void 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. The value and traceback object may be NULL even when the type object is not. // // Note This function is normally only used by code that needs to handle exceptions or by code that needs to save and restore the error indicator temporarily. func PyErr_Fetch() (exc, val, tb *PyObject) { C.PyErr_Fetch(&exc.ptr, &val.ptr, &tb.ptr) return }