[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyKDE] SIP Support for C++ Operators and Exceptions
From:       Phil Thompson <phil () riverbankcomputing ! co ! uk>
Date:       2003-07-25 15:30:01
[Download RAW message or body]

On Friday 25 July 2003 1:51 pm, Paul F. Kunz wrote:
> >>>>> On Fri, 25 Jul 2003 09:48:59 +0100, Phil Thompson
> >>>>> <phil@riverbankcomputing.co.uk> said:
> >
> > On Friday 25 July 2003 12:01 am, Tuvi, Selim wrote:
> >> Phil, we just tried your suggestion and added a wrapped exception
> >> class and enabled the -e flag.
> >>
> >> Although it does translate the C++ exception to Python properly, it
> >> does it a little different than the regular Python exceptions
> >> would. In Python, one would write:
> >>
> >> try: raise RuntimeError, "Got an error" except RuntimeError,
> >> detail: print detail
> >>
> >> When run, this would print "Got an error".
> >>
> >> But when the C++ exception is received by Python, "print detail"
> >> returns the class instance of the wrapped exception object. Is
> >> there a seamless way of having Python display the error message
> >> rather than the class instance reference? If the person who wrote
> >> the python code did not provide the try/except block then all
> >> he/she would see is going to be the name of the class which is not
> >> very informative.
> >
> > What if you implement __str__() for your exception class?
>
>    I suppose you mean to implement this in the .sip file.   Can you
> point to an example of doing this in the PyQt sources?

grep __str__ *.sip => qbytearray.sip, qcstring.sip, qstring.sip

The important bits are that "sipCpp" will be a pointer to your exception class 
instance and you should return a Python string or Unicode object.

Phil

_______________________________________________
PyKDE mailing list    PyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic