[PyQt] Problem with exception translation

Phil Thompson phil at riverbankcomputing.com
Tue Sep 14 10:51:09 BST 2010


On Thu, 9 Sep 2010 15:59:04 +0200, Hans Meine
<meine at informatik.uni-hamburg.de> wrote:
> Hi,
> 
> I have had many problems with exception translation.  First of all, it
> seems 
> to be an undocumented fact that the exception translation is overwritten
> by 
> %MethodCode blocks (i.e. not wrapped around them).
> 
> Second, even after enabling exception translation by passing -e and
> describing 
> my exception (or std::exception, which is the base class) using an
> %Exception 
> block, it is not caught anywhere, obviously because I have no throw(...)

> clauses.  (Luckily, I later found /Default/, see below.)
> 
> Third, I have had problems when trying to add throw(...) clauses, i.e. I
> have
>   
>   class Foo : QObject
>   {
>     void test() throw (std::exception);
>   };
> 
>   %Exception std::exception(SIP_Exception)
>   {
>   %TypeHeaderCode
>   #include <exception>
>   %End
> 
>   %RaiseCode
>     const char *detail = sipExceptionRef.what();
> 
>     SIP_BLOCK_THREADS
>     PyErr_SetString(PyExc_RuntimeError, detail);
>     SIP_UNBLOCK_THREADS
>   %End
>   };
> 
> But I am getting:
> sip: ..:14: There is already a class or namespace in scope with the same

> Python name
> 
> Ah!  The error goes away when I swap the two declarations, i.e. move the

> %Exception block above.
> 
> Anyhow, now I found the /Default/ annotation, which is exactly what I
> want.  
> However, I get compile errors from the generated code; obviously, the
> above 
> %TypeHeaderCode is not inserted into every file using the above
> default-catch 
> block, so #include <exception> is missing and the build fails.
> 
> At least the latter seems to be a clear bug to me, no?

In the above Foo doesn't have a %TypeHeaderCode block. I would expect that
it's .h file would #include <exception>...

...unless exceptions in a throw() can be only partially defined (like
pointers to classes can)?

Phil


More information about the PyQt mailing list