Commit 390b35a9 authored by Lars Buitinck's avatar Lars Buitinck Committed by Lars Buitinck

Add tests for fine-grained exception handling

parent e71d885b
...@@ -12,12 +12,45 @@ cdef extern from "cpp_exceptions_helper.h": ...@@ -12,12 +12,45 @@ cdef extern from "cpp_exceptions_helper.h":
cdef int raise_index_value "raise_index"(bint fire) except +ValueError cdef int raise_index_value "raise_index"(bint fire) except +ValueError
cdef int raise_index_custom "raise_index"(bint fire) except +raise_py_error cdef int raise_index_custom "raise_index"(bint fire) except +raise_py_error
cdef void raise_arithmetic "raise_arithmetic"() except +
cdef void raise_memory "raise_memory"() except +
cdef void raise_overflow "raise_overflow"() except +
cdef cppclass Foo: cdef cppclass Foo:
int bar_raw "bar"(bint fire) except + int bar_raw "bar"(bint fire) except +
int bar_value "bar"(bint fire) except +ValueError int bar_value "bar"(bint fire) except +ValueError
int bar_custom "bar"(bint fire) except +raise_py_error int bar_custom "bar"(bint fire) except +raise_py_error
def test_arithmetic():
"""
>>> test_arithmetic()
Traceback (most recent call last):
...
ArithmeticError: range_error
"""
raise_arithmetic()
# XXX The following error message is actually implementation-defined.
# This is the one from GCC/libstdc++ 4.4.5 on Linux.
def test_memory():
"""
>>> test_memory()
Traceback (most recent call last):
...
MemoryError: std::bad_alloc
"""
raise_memory()
def test_overflow():
"""
>>> test_overflow()
Traceback (most recent call last):
...
OverflowError: overflow_error
"""
raise_overflow()
def test_int_raw(bint fire): def test_int_raw(bint fire):
""" """
>>> test_int_raw(False) >>> test_int_raw(False)
......
...@@ -23,3 +23,17 @@ class Foo { ...@@ -23,3 +23,17 @@ class Foo {
return 0; return 0;
} }
}; };
void raise_arithmetic() {
throw std::range_error("range_error");
}
void raise_memory() {
// std::bad_alloc can only be default constructed,
// so we have no control over the error message
throw std::bad_alloc();
}
void raise_overflow() {
throw std::overflow_error("overflow_error");
}
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