【发布时间】:2010-11-27 22:18:04
【问题描述】:
我想在我的 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;
}
PyErr_Print() 只是将错误文本打印到 stderr 并清除错误,因此无法解决
【问题讨论】:
标签: c++ python exception boost-python