summaryrefslogtreecommitdiff
path: root/tests/run
diff options
context:
space:
mode:
authorRobert Bradshaw <robertwb@google.com>2018-09-17 16:30:51 +0200
committerRobert Bradshaw <robertwb@google.com>2018-09-17 16:51:33 +0200
commitf61160ede013d48f28c033d5ba64a9910d2dd79c (patch)
tree5b58abbef7600835cad2a99ae1f49f1f1ce2f1e4 /tests/run
parent76a8e08fc4fb7fb48e621d8360bfd6f6415258d5 (diff)
downloadcython-f61160ede013d48f28c033d5ba64a9910d2dd79c.tar.gz
Catch Python exceptions for object-returning except+ functions.
Fixes Github issue #2603.
Diffstat (limited to 'tests/run')
-rw-r--r--tests/run/cpp_exceptions.pyx16
-rw-r--r--tests/run/cpp_exceptions_helper.h9
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/run/cpp_exceptions.pyx b/tests/run/cpp_exceptions.pyx
index 4854aa1cb..1901cf4b7 100644
--- a/tests/run/cpp_exceptions.pyx
+++ b/tests/run/cpp_exceptions.pyx
@@ -21,6 +21,8 @@ cdef extern from "cpp_exceptions_helper.h":
cdef void raise_typeerror() except +
cdef void raise_underflow() except +
+ cdef object raise_py(bint fire_py) except +
+
cdef cppclass Foo:
int bar_raw "bar"(bint fire) except +
int bar_value "bar"(bint fire) except +ValueError
@@ -199,3 +201,17 @@ def test_cppclass_method_custom(bint fire):
foo.bar_custom(fire)
finally:
del foo
+
+def test_py(bint py_fire):
+ """
+ >>> test_py(True)
+ Traceback (most recent call last):
+ ...
+ RuntimeError: py error
+
+ >>> test_py(False)
+ Traceback (most recent call last):
+ ...
+ IndexError: c++ error
+ """
+ raise_py(py_fire)
diff --git a/tests/run/cpp_exceptions_helper.h b/tests/run/cpp_exceptions_helper.h
index aa4e505f5..7058aedaa 100644
--- a/tests/run/cpp_exceptions_helper.h
+++ b/tests/run/cpp_exceptions_helper.h
@@ -61,3 +61,12 @@ void raise_typeerror() {
void raise_underflow() {
throw std::underflow_error("underflow_error");
}
+
+PyObject* raise_py(int fire_py) {
+ if (fire_py) {
+ PyErr_SetString(PyExc_RuntimeError, "py error");
+ return NULL;
+ } else {
+ throw std::out_of_range("c++ error");
+ }
+}