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
Gwenaël Samain
cython
Commits
c3cc3617
Commit
c3cc3617
authored
Jun 30, 2011
by
Lars Buitinck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
C++ exceptions: handle domain error
parent
6291a297
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
11 deletions
+26
-11
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+6
-5
tests/run/cpp_exceptions.pyx
tests/run/cpp_exceptions.pyx
+16
-6
tests/run/cpp_exceptions_helper.h
tests/run/cpp_exceptions_helper.h
+4
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
c3cc3617
...
...
@@ -8216,20 +8216,21 @@ cpp_exception_utility_code = UtilityCode(
proto
=
"""
#ifndef __Pyx_CppExn2PyErr
static void __Pyx_CppExn2PyErr() {
// Catch a handful of different errors here and turn them into the
// equivalent Python errors.
try {
if (PyErr_Occurred())
; // let the latest Python exn pass through and ignore the current one
else
throw;
} catch (const std::invalid_argument& exn) {
// Catch a handful of different errors here and turn them into the
// equivalent Python errors.
// Change invalid_argument to ValueError
PyErr_SetString(PyExc_ValueError, exn.what());
} catch (const std::bad_alloc& exn) {
PyErr_SetString(PyExc_MemoryError, exn.what());
} catch (const std::bad_cast& exn) {
PyErr_SetString(PyExc_TypeError, exn.what());
} catch (const std::domain_error& exn) {
PyErr_SetString(PyExc_ValueError, exn.what());
} catch (const std::invalid_argument& exn) {
PyErr_SetString(PyExc_ValueError, exn.what());
} catch (const std::ios_base::failure& exn) {
// Unfortunately, in standard C++ we have no way of distinguishing EOF
// from other errors here; be careful with the exception mask
...
...
tests/run/cpp_exceptions.pyx
View file @
c3cc3617
...
...
@@ -12,12 +12,13 @@ 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_ios_failure
"raise_ios_failure"
()
except
+
cdef
void
raise_memory
"raise_memory"
()
except
+
cdef
void
raise_overflow
"raise_overflow"
()
except
+
cdef
void
raise_range_error
"raise_range_error"
()
except
+
cdef
void
raise_typeerror
"raise_typeerror"
()
except
+
cdef
void
raise_underflow
"raise_underflow"
()
except
+
cdef
void
raise_domain_error
()
except
+
cdef
void
raise_ios_failure
()
except
+
cdef
void
raise_memory
()
except
+
cdef
void
raise_overflow
()
except
+
cdef
void
raise_range_error
()
except
+
cdef
void
raise_typeerror
()
except
+
cdef
void
raise_underflow
()
except
+
cdef
cppclass
Foo
:
int
bar_raw
"bar"
(
bint
fire
)
except
+
...
...
@@ -25,6 +26,15 @@ cdef extern from "cpp_exceptions_helper.h":
int
bar_custom
"bar"
(
bint
fire
)
except
+
raise_py_error
def
test_domain_error
():
"""
>>> test_domain_error()
Traceback (most recent call last):
...
ValueError: domain_error
"""
raise_domain_error
()
def
test_ios_failure
():
"""
>>> test_ios_failure()
...
...
tests/run/cpp_exceptions_helper.h
View file @
c3cc3617
...
...
@@ -26,6 +26,10 @@ class Foo {
}
};
void
raise_domain_error
()
{
throw
std
::
domain_error
(
"domain_error"
);
}
void
raise_ios_failure
()
{
throw
std
::
ios_base
::
failure
(
"iostream failure"
);
}
...
...
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