diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index 16f1d6b290..d493f1f68d 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -134,6 +134,17 @@ private: PyGILState_STATE _state; }; +static void pyRaiseCVException(const cv::Exception &e) +{ + PyObject_SetAttrString(opencv_error, "file", PyString_FromString(e.file.c_str())); + PyObject_SetAttrString(opencv_error, "func", PyString_FromString(e.func.c_str())); + PyObject_SetAttrString(opencv_error, "line", PyInt_FromLong(e.line)); + PyObject_SetAttrString(opencv_error, "code", PyInt_FromLong(e.code)); + PyObject_SetAttrString(opencv_error, "msg", PyString_FromString(e.msg.c_str())); + PyObject_SetAttrString(opencv_error, "err", PyString_FromString(e.err.c_str())); + PyErr_SetString(opencv_error, e.what()); +} + #define ERRWRAP2(expr) \ try \ { \ @@ -142,13 +153,7 @@ try \ } \ catch (const cv::Exception &e) \ { \ - PyObject_SetAttrString(opencv_error, "file", PyString_FromString(e.file.c_str())); \ - PyObject_SetAttrString(opencv_error, "func", PyString_FromString(e.func.c_str())); \ - PyObject_SetAttrString(opencv_error, "line", PyInt_FromLong(e.line)); \ - PyObject_SetAttrString(opencv_error, "code", PyInt_FromLong(e.code)); \ - PyObject_SetAttrString(opencv_error, "msg", PyString_FromString(e.msg.c_str())); \ - PyObject_SetAttrString(opencv_error, "err", PyString_FromString(e.err.c_str())); \ - PyErr_SetString(opencv_error, e.what()); \ + pyRaiseCVException(e); \ return 0; \ }