1, if the General console program, you can use Pyerr_print (); Error messages will print directly to the console
2, if not console program, you need to use Pyerr_fetch (pyobject**,pyobject**,pyobject**,pyobject**)
Here is the code example: (from Stack Overflow)
char* Full_backtrace; Save Traceback
pyobject* Ptype,*pvalue,*ptraceback;
pyobject* Pystr,*module_name,*pyth_module,*pyth_func;
Char *str;
Pyerr_fetch (&ptype,&pvalue,&ptraceback);
Pystr = Pyobject_str (pvalue);
Str= pystring_asstring (PYSTR);
char* error_description = StrDup (str);
Module_name = pystring_fromstring ("Traceback");
Pyth_module = Pyimport_import (module_name);
Py_decref (module_name);
if (Pyth_module = = NULL) {
Full_backtrace = NULL;
Return
}
Pyth_func = pyobject_getattrstring (Pyth_module, "format_exception");
if (Pyth_func && Pycallable_check (pyth_func)) {
Pyobject *pyth_val;
Pyth_val = Pyobject_callfunctionobjargs (Pyth_func, PType, Pvalue, Ptraceback, NULL);
Pystr = Pyobject_str (pyth_val);
str = pystring_asstring (PYSTR);
Full_backtrace = StrDup (str);
Py_decref (Pyth_val);
}
C Gets the traceback of the python exception