|
embedding: getting exception information?: msg#00337python.c++
Hi, I'm embedding python in a COM object and want to get the information usually printed via PyErr_Print. I tried code like this: dict ns(... dict of __main__ like in the example ...); try { handle<>(PyRun_String("import non_existing_module\n", Py_file_input,ns.ptr(),ns.ptr())); } catch (error_already_set) { // try to write error information to StringIO buffer PyRun_String("import traceback,sys,StringIO\n" "buf = StringIO.StringIO()\n" "traceback.print_tb(sys.exc_info()[2],None,buf)\n" "error = buf.getvalue()\n", Py_file_input,ns.ptr(),ns.ptr()); PyErr_Clear(); std::string error = extract<std::string>(ns["error"]); } I tried also to use extract<const char*> but in both cases I get an exception in this line. I first tried to get the error information using the C API, but I could not find a solution. Af a little bit of googling I found this solution, but I don't know if it's ok: There is still an active exception, so could I safely continue to use the interpreter to output the error? Has somebody an working example on how to get the traceback or could point me to the right direction? regards, Achim |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Re: accessing the python type system: 00337, Stefan Seefeld |
|---|---|
| Next by Date: | Re: Projects Page Reminder: 00337, David Abrahams |
| Previous by Thread: | Projects Page Reminderi: 00337, David Abrahams |
| Next by Thread: | Re: embedding: getting exception information?: 00337, David Abrahams |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |