summaryrefslogtreecommitdiff
path: root/numpy/f2py/rules.py
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2019-12-05 13:26:44 +0200
committerGitHub <noreply@github.com>2019-12-05 13:26:44 +0200
commit1783e6fc437f34af1d652cbae36a68abcbf41fbc (patch)
tree4bce264cfcafca39df9fe41fa96d6a009017523e /numpy/f2py/rules.py
parent9a79803e5edd0819bfa4c19a3442f75209fee5ec (diff)
parent3c6bbd7b43bf584aeef780a9e42acf2ecce7b179 (diff)
downloadnumpy-1783e6fc437f34af1d652cbae36a68abcbf41fbc.tar.gz
Merge pull request #15022 from eric-wieser/better-f2py-error
ENH: f2py: improve error messages
Diffstat (limited to 'numpy/f2py/rules.py')
-rwxr-xr-xnumpy/f2py/rules.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/numpy/f2py/rules.py b/numpy/f2py/rules.py
index f2f713bde..28eb9da30 100755
--- a/numpy/f2py/rules.py
+++ b/numpy/f2py/rules.py
@@ -1064,8 +1064,10 @@ if (#varname#_capi==Py_None) {
'\tcapi_#varname#_tmp = array_from_pyobj(#atype#,#varname#_Dims,#varname#_Rank,capi_#varname#_intent,#varname#_capi);'},
"""\
\tif (capi_#varname#_tmp == NULL) {
-\t\tif (!PyErr_Occurred())
-\t\t\tPyErr_SetString(#modulename#_error,\"failed in converting #nth# `#varname#\' of #pyname# to C/Fortran array\" );
+\t\tPyObject *exc, *val, *tb;
+\t\tPyErr_Fetch(&exc, &val, &tb);
+\t\tPyErr_SetString(exc ? exc : #modulename#_error,\"failed in converting #nth# `#varname#\' of #pyname# to C/Fortran array\" );
+\t\tnpy_PyErr_ChainExceptionsCause(exc, val, tb);
\t} else {
\t\t#varname# = (#ctype# *)(PyArray_DATA(capi_#varname#_tmp));
""",
@@ -1081,8 +1083,10 @@ if (#varname#_capi==Py_None) {
\t\t\twhile ((_i = nextforcomb()))
\t\t\t\t#varname#[capi_i++] = #init#; /* fortran way */
\t\t} else {
-\t\t\tif (!PyErr_Occurred())
-\t\t\t\tPyErr_SetString(#modulename#_error,\"Initialization of #nth# #varname# failed (initforcomb).\");
+\t\t\tPyObject *exc, *val, *tb;
+\t\t\tPyErr_Fetch(&exc, &val, &tb);
+\t\t\tPyErr_SetString(exc ? exc : #modulename#_error,\"Initialization of #nth# #varname# failed (initforcomb).\");
+\t\t\tnpy_PyErr_ChainExceptionsCause(exc, val, tb);
\t\t\tf2py_success = 0;
\t\t}
\t}