[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:       "Tuvi, Selim" <stuvi () SLAC ! Stanford ! EDU>
Date:       2003-07-24 23:01:54
[Download RAW message or body]

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.

Thanks
-Selim

Selim Tuvi, Research Engineering Group, SLAC
GLAST, I&T Online, MS 98
Tel:650-926-3376 Fax:650-926-4335
 

-----Original Message-----
From: Phil Thompson [mailto:phil@river-bank.demon.co.uk] 
Sent: Wednesday, April 23, 2003 2:40 PM
To: jbublitz@nwinternet.com
Cc: pykde@mats.gmd.de
Subject: Re: [PyKDE] SIP Support for C++ Operators and Exceptions


On Wednesday 23 April 2003 9:03 pm, Jim Bublitz wrote:
> On 23-Apr-03 Phil Thompson wrote:
> > Tonight's SIP snapshot supports C++ operators and exceptions.
> > 
> > Thanks to Oliver Kohlbacher for contributing the exception support 
> > (enabled through the new -e flag to SIP). However, my integration of 
> > it is completely untested - over to you Oliver.
> 
> Could you or Oliver provide a little more detail? For example, if 
> exception support is enabled, will C++ exceptions be converted to 
> Python exceptions? Is this automatically global support, or does it 
> need to be enabled per module, class, method, ? with a sip keyword? 
> Thanks in advance.

The -e flag enables the generation of try/catch blocks around *all* calls to 
wrapped functions for that module. You can include throw specifiers in .sip 
files. eg.

	void foo() throw (bar);

"bar" must also be defined as a wrapped class and is converted to a Python 
object when caught.

Try running with the -e flag added and have a look at the generated code.

Phil

_______________________________________________
PyKDE mailing list    PyKDE@mats.gmd.de
http://mats.gmd.de/mailman/listinfo/pykde

_______________________________________________
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