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
Xavier Thompson
cython
Commits
a1cfa834
Commit
a1cfa834
authored
Jun 30, 2011
by
Lars Buitinck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
document fine-grained C++ exceptions in the user guide
parent
c3cc3617
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
3 deletions
+31
-3
docs/src/userguide/wrapping_CPlusPlus.rst
docs/src/userguide/wrapping_CPlusPlus.rst
+31
-3
No files found.
docs/src/userguide/wrapping_CPlusPlus.rst
View file @
a1cfa834
...
...
@@ -359,9 +359,37 @@ exception and converting it into a Python exception. For example, ::
cdef extern from "some_file.h":
cdef int foo() except +
This will translate try and the C++ error into an appropriate Python exception
(currently an IndexError on std::out_of_range and a RuntimeError otherwise
(preserving the what() message). ::
This will translate try and the C++ error into an appropriate Python exception.
The translation is performed according to the following table
(the ``std::`` prefix is omitted from the C++ identifiers):
+-----------------------+---------------------+
| C++ | Python |
+=======================+=====================+
| ``bad_alloc`` | ``MemoryError`` |
+-----------------------+---------------------+
| ``bad_cast`` | ``TypeError`` |
+-----------------------+---------------------+
| ``domain_error`` | ``ValueError`` |
+-----------------------+---------------------+
| ``invalid_argument`` | ``ValueError`` |
+-----------------------+---------------------+
| ``ios_base::failure`` | ``IOError`` |
+-----------------------+---------------------+
| ``out_of_range`` | ``IndexError`` |
+-----------------------+---------------------+
| ``overflow_error`` | ``OverflowError`` |
+-----------------------+---------------------+
| ``range_error`` | ``ArithmeticError`` |
+-----------------------+---------------------+
| ``underflow_error`` | ``ArithmeticError`` |
+-----------------------+---------------------+
| (all others) | ``RuntimeError`` |
+-----------------------+---------------------+
The ``what()`` message, if any, is preserved. Note that a C++
``ios_base_failure`` can denote EOF, but does not carry enough information
for Cython to discern that, so watch out with exception masks on IO streams. ::
cdef int bar() except +MemoryError
...
...
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