Ctypes catching exception

后端 未结 2 585
执笔经年
执笔经年 2020-12-21 01:51

I\'m playing a little bit with ctypes and C/C++ DLLs I have a quite simple \"math\" dll

double Divide(double a, double b)
{
    if (b == 0)
    {
       thro         


        
2条回答
  •  星月不相逢
    2020-12-21 02:40

    Try this:

    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 as we:
        print we.args[0]
    except:
        print "Unhandled Exception"
    

提交回复
热议问题