retrieve traceback in embedded python of Python3.0?

B

BigHand

Guys:
I have a embedded python in MFC app. to execute a py script of a.py,
the is only one line in a.py, it "a()" , normally ,excute this script
file ,you will get a
"the exception type is<class 'NameError'> "
"The exception value is name 'a' is not defined "


Python3.0 with VS2005.
here is the brief code:
Py_Initialize();
PyObject *m, *d, *v;
m = PyImport_AddModule("__main__");
d = PyModule_GetDict(m);
v = PyRun_File(fp, pStr, Py_file_input, d, d); //~~~the py
script is a.py
PyObject *exc_type = NULL, *exc_value = NULL, *exc_tb = NULL;
PyErr_Fetch(&exc_type, &exc_value, &exc_tb); //~~~after fetch , the
exc_type, exc_value, exc_tb are not "NULL"
PyObject * modTB = PyImport_ImportModule("traceback");
PyObject* pyUStr = PyUnicode_FromString("format_exception");
PyObject* listTB = PyObject_CallMethodObjArgs(modTB, pyUStr,
exc_type, exc_value, exc_tb, NULL);

in the PyObject_CallMethodObjArgs(modTB, pyUStr, exc_type, exc_value,
exc_tb, NULL), I get modTB, pyUStr, exc_type, exc_value, exc_tb are
not NULL, but the listTB is always NULL, I can retrieve the list...

any body could enlight me?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top