Is there any way to catch expections when call python method in C++

cptnwillard at gmail.com cptnwillard at gmail.com
Wed Jun 13 14:01:18 CEST 2007


One way is to create an intermediate python function, which returns a
special value when an exception is caught.

def ExceptionCatcher(FunctionToCall):
    def F():
        try: FunctionToCall()
        except: return -1
        return 0
    return F

Then instead of calling your function, you would call
ExceptionCatcher(YourFunction). You can then check the return value in
your C++ code.




More information about the Python-list mailing list