我正在玩一点 ctypes 和 C/C++ DLL 我有一个非常简单的“数学”DLL
double Divide(double a, double b)
{
if (b == 0)
{
throw new invalid_argument("b cannot be zero!");
}
return a / b;
}
到目前为止唯一的问题是,我在 Python 中得到一个 WindowsError 异常,我无法检索文本 b 不能为零 是否有一些特殊的异常类型我必须抛出?还是必须更改 Python 代码?蟒蛇代码:
from ctypes import *
mathdll=cdll.MathFuncsDll
divide = mathdll.Divide
divide.restype = c_double
divide.argtypes = [c_double, c_double]
try:
print divide (10,0)
except WindowsError:
print "lalal"
except:
print "dada"