【发布时间】:2015-09-04 06:35:43
【问题描述】:
我想在我的 C++ 应用程序中嵌入 python。我不使用 Boost 库。
如果 C++ 函数抛出异常,我想捕获它并在我的应用程序中打印错误,或者获取一些详细信息,例如导致错误的 python 脚本中的行号。
我该怎么做?我在 Python API 或 C++ 中找不到任何函数来获取详细的异常信息。
void sum(int iA, int iB)
{
throw iA + iB;
}
from ctypes import *
mydll = WinDLL("C:\\Users\\cppwrapper.dll")
try:
mydll.sum(2,3)
catch:
print "exception occured"
但它不起作用。请帮我解决这个问题。提前致谢。
【问题讨论】: