Commit a19b8a99 authored by Matt Wozniski's avatar Matt Wozniski

Test an "except +" function returning <object>NULL

This provides a test case for #2603
parent a47d63eb
......@@ -21,6 +21,8 @@ cdef extern from "cpp_exceptions_helper.h":
cdef void raise_typeerror() except +
cdef void raise_underflow() except +
cdef raise_or_throw(bint py) except +
cdef cppclass Foo:
int bar_raw "bar"(bint fire) except +
int bar_value "bar"(bint fire) except +ValueError
......@@ -98,6 +100,19 @@ def test_underflow():
"""
raise_underflow()
def test_func_that_can_raise_or_throw(bint py):
"""
>>> test_func_that_can_raise_or_throw(0)
Traceback (most recent call last):
...
RuntimeError: oopsie
>>> test_func_that_can_raise_or_throw(1)
Traceback (most recent call last):
...
ValueError: oopsie
"""
raise_or_throw(py)
def test_int_raw(bint fire):
"""
>>> test_int_raw(False)
......
#include <Python.h>
#include <ios>
#include <new>
#include <stdexcept>
......@@ -61,3 +62,11 @@ void raise_typeerror() {
void raise_underflow() {
throw std::underflow_error("underflow_error");
}
PyObject *raise_or_throw(int py) {
if (!py) {
throw std::runtime_error("oopsie");
}
PyErr_SetString(PyExc_ValueError, "oopsie");
return NULL;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment