[Cython] Higher fidelity translations from C++ exception to Python exception?
Dag Sverre Seljebotn
d.s.seljebotn at astro.uio.no
Fri Jul 6 23:59:51 CEST 2012
Barry Warsaw <barry at python.org> wrote:
>So if you have code like the following:
>
>cdef class Database:
> cdef open(self, path) except +raise_py_error:
> something_that_can_throw_a_cpp_exception(path)
>
>you can write
>
>cdef int raise_py_error():
> raise Something
>
>to kind of turn a C++ exception into a Python exception. The problem
>appears
>to be that you cannot include in the Python exception any information
>contained in the C++ exception, because there's no access to the C++
>exception
>that was thrown.
>
>The generated code does a `catch(...)` so you lose that useful
>information.
>AFAICT, there's no way to find out within the catch clause (or anything
>called
>by that clause) what C++ exception occurred.
>
>It would sure be useful if raise_py_error() was passed the exception
>instance
>that was caught. Then at least our handler could extract some useful
>information to relay to the Python level. E.g. in the case above, it
>might
>tell us that the `path` is nonexistent.
But that requires something more than a catch(...), right? There must be more syntax introduced in the Cython language to map C++ exceptions to constructor functions (taking exceptions of different types). Do you have a concrete proposal for how that could look like?
Dag
>
>Cheers,
>-Barry
>_______________________________________________
>cython-devel mailing list
>cython-devel at python.org
>http://mail.python.org/mailman/listinfo/cython-devel
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
More information about the cython-devel
mailing list