[PyKDE] SIP Support for C++ Operators and Exceptions

Tuvi, Selim stuvi at SLAC.Stanford.EDU
Fri Jul 25 01:03:01 BST 2003


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 at river-bank.demon.co.uk] 
Sent: Wednesday, April 23, 2003 2:40 PM
To: jbublitz at nwinternet.com
Cc: pykde at 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 at mats.gmd.de
http://mats.gmd.de/mailman/listinfo/pykde




More information about the PyQt mailing list