我想在我的C++应用程序中嵌入python.我正在使用Boost库 - 很棒的工具.但我有一个问题.
如果python函数抛出异常,我想抓住它并在我的应用程序中打印错误或获取一些详细信息,如python脚本中的行号导致错误.
我该怎么做?我找不到任何函数来获取Python API或Boost中的详细异常信息.
try {
module=import("MyModule"); //this line will throw excetion if MyModule contains an error
} catch ( error_already_set const & ) {
//Here i can said that i have error, but i cant determine what caused an error
std::cout << "error!" << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
PyErr_Print()只是将错误文本输出到stderr并清除错误,因此无法解决问题