How do I propagate C++ exceptions to Python in a SWIG wrapper library?

后端 未结 6 1218
天涯浪人
天涯浪人 2020-12-13 04:54

I\'m writing a SWIG wrapper around a custom C++ library which defines its own C++ exception types. The library\'s exception types are richer and more specific than standard

6条回答
  •  忘掉有多难
    2020-12-13 05:16

    From the swig documentation

    %except(python) {
    try {
    $function
    }
    catch (RangeError) {
        PyErr_SetString(PyExc_IndexError,"index out-of-bounds");
        return NULL;
    }
    }
    

提交回复
热议问题