Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
390b35a9
Commit
390b35a9
authored
Jun 29, 2011
by
Lars Buitinck
Committed by
Lars Buitinck
Jun 29, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for fine-grained exception handling
parent
e71d885b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
0 deletions
+47
-0
tests/run/cpp_exceptions.pyx
tests/run/cpp_exceptions.pyx
+33
-0
tests/run/cpp_exceptions_helper.h
tests/run/cpp_exceptions_helper.h
+14
-0
No files found.
tests/run/cpp_exceptions.pyx
View file @
390b35a9
...
...
@@ -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_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
:
int
bar_raw
"bar"
(
bint
fire
)
except
+
int
bar_value
"bar"
(
bint
fire
)
except
+
ValueError
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
):
"""
>>> test_int_raw(False)
...
...
tests/run/cpp_exceptions_helper.h
View file @
390b35a9
...
...
@@ -23,3 +23,17 @@ class Foo {
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"
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment