From 090994a1a3cbcfaebc9ab7f934fffb3c0a5ccc07 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 10 Jul 2019 15:56:07 -0400 Subject: [PATCH] propagate exceptions from global functions from cpp to python --- wrap/GlobalFunction.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/wrap/GlobalFunction.cpp b/wrap/GlobalFunction.cpp index 13616d64a..02ab19657 100644 --- a/wrap/GlobalFunction.cpp +++ b/wrap/GlobalFunction.cpp @@ -143,6 +143,7 @@ void GlobalFunction::emit_cython_pxd(FileWriter& file) const { "\"("; argumentList(i).emit_cython_pxd(file, "", vector()); file.oss << ")"; + file.oss << " except +"; file.oss << "\n"; } } @@ -206,16 +207,18 @@ void GlobalFunction::emit_cython_pyx(FileWriter& file) const { /// Call corresponding cython function file.oss << argumentList(i).pyx_convertEigenTypeAndStorageOrder(" "); - string call = pyx_functionCall("", pxdName(), i); - if (!returnVals_[i].isVoid()) { - file.oss << " return_value = " << call << "\n"; - file.oss << " return True, " << returnVals_[i].pyx_casting("return_value") << "\n"; - } else { - file.oss << " " << call << "\n"; - file.oss << " return True, None\n"; - } + // catch exception which indicates the parameters passed are incorrect. file.oss << " except:\n"; file.oss << " return False, None\n\n"; + + string call = pyx_functionCall("", pxdName(), i); + if (!returnVals_[i].isVoid()) { + file.oss << " return_value = " << call << "\n"; + file.oss << " return True, " << returnVals_[i].pyx_casting("return_value") << "\n"; + } else { + file.oss << " " << call << "\n"; + file.oss << " return True, None\n"; + } } } /* ************************************************************************* */