[PyKDE] Handling exceptions in SIP

Denis S. Otkidach ods at strana.ru
Sat Jun 18 09:49:23 BST 2005


On Thu, 9 Jun 2005 09:33:22 -0700
James Emerton <ephelon at gmail.com> wrote:

> I think there is a need for biderectional conversion of exceptions. 
> I'd like to be able to throw them back into the C++.
> 
> In fact, a mechanism that could be enable to check the Python error
> state after calling a Python method from C++ could throw the exception
> instead of returning to the C++.

Could you provide some examples?  I see 2 use cases:

1) Your C++ method accepts callback function implemented in Python.  SIP
translates C++ functions to Python, but it doesn't translate Python
callables to C++ ones.  You have to call it yourself.  There is no even
automatic argument translation for it.  Why do you think exception
should be translated automatically?  You can never trust user provided
Python code, you can't predict what exceptions it will ever raise, so
you have to handle all possible errors.  I even can't imaging syntax for
backward exception translation.

2) You overwrite virtual method of wrapped class in Python, so that
other methods (implemented in C++) use it instead of base.  This is more
interesting case, but I believe SIP can't handle it too.  Please correct
me if I'm wrong.

So far I don't see any need for automatic backward exception
translation, since you have to code mannually Python exception handling
anyway.

-- 
Denis S. Otkidach
http://www.python.ru/      [ru]




More information about the PyQt mailing list