Wednesday 15 September 2010

c++ - boost python error message:terminate called after throwing an instance of 'boost::python::error_already_set' -



c++ - boost python error message:terminate called after throwing an instance of 'boost::python::error_already_set' -

i have main.py loaded in c++ , run

void runscript ( std::string script ) { seek { pyrun_simplestringflags ( script.c_str() ,null ); } grab ( const boost::python::error_already_set& ) { std::cout<<"test error"<<std::endl; } }

the main.py has line:

import test

(which test.py) located in same folder within main.py. when test.py has error cannot cach error got, application crash with:

terminate called after throwing instance of 'boost::python::error_already_set'

is there way cache file or line got error?

you can utilize eval or exec instead (doc reference).

try { bp::exec(script); } grab (bp::error_already_set) { }

the real problem getting error info exception object.

it's easy print exception stdout pyerr_print() catch block, if need more complicated analysis code becomes cumbersome.

in catch block have exception info pyerr_fetch, normalize pyerr_normalizeexception and, say, analyze phone call stack iterating on traceback objects.

python c++ boost

No comments:

Post a Comment