<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Thanks so much, Phil!<br>
<br>
That's exactly where the problem was! All I had to do is to change:<br>
const std::string sgRole() const;<br>
to<br>
const std::string sgRole() const
throw(TipShotgun::Shotgun::Exception);<br>
<br>
Thanks!!<br>
<br>
-Jean<br>
<br>
<br>
Phil Thompson wrote:
<blockquote cite="mid:7002e561c4b04e9759300490b2ce28df@localhost"
type="cite">
<pre wrap="">On Wed, 19 May 2010 16:02:38 -0700, Qin Shen <a class="moz-txt-link-rfc2396E" href="mailto:jeanshen@tippett.com"><jeanshen@tippett.com></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi there,
I'm fairly new on SIP and haven't done any development on PyQt.
But I'm using SIP to write a python wrapper for our C++ library.
I have tried to translate the C++ exceptions to Python exceptions.
So far I managed to get it to work, but I had to change the
auto-generated sipcode, which is not what I wanted. The following
is what I did, could any of you tell me what I have missed and
how I can avoid manually changing the generated sipcode?
(1) The .sip file
--------------------------------------------------
%Exception TipShotgun::Shotgun::Exception(SIP_Exception)
/PyName=ShotgunException/
{
%TypeHeaderCode
#include <TipShotgun/Shotgun.h>
%End
%RaiseCode
const char *detail = sipExceptionRef.what();
SIP_BLOCK_THREADS
PyErr_SetString(sipException_TipShotgun_Shotgun_Exception,
</pre>
</blockquote>
<pre wrap=""><!---->detail);
</pre>
<blockquote type="cite">
<pre wrap=""> SIP_UNBLOCK_THREADS
%End
};
(2) I run "sip" command with the "-e" flag which enables the support
for C++ exceptions. The auto-generated sip .cpp code looks like
this BEFORE I made any changes manually.
--------------------------------------------------
try
{
sipRes = new std::string(sipCpp->sgRole());
}
catch (...)
{
sipRaiseUnknownException();
return NULL;
}
(3) Here is the sip .cpp code AFTER I added the changes.
---------------------------------------------------------
try
{
sipRes = new std::string(sipCpp->sgRole());
}
catch (TipShotgun::Shotgun::Exception &error)
{
PyErr_SetString(sipException_TipShotgun_Shotgun_Exception,
error.what());
return NULL;
}
catch (...)
{
sipRaiseUnknownException();
return NULL;
}
(4) My python test script
----------------------------------------------------------
#!/usr/bin/env python
from _shotgun import *
sg = TipShotgun.Shotgun()
user = sg.findUserByLogin("farny")
try:
role = user.sgRole()
except ShotgunException, err:
print err
print
print "THE END OF TEST"
-------------------------------------------------------
With (1), (3) & (4), everything works fine. Without the manual updates
</pre>
</blockquote>
<pre wrap=""><!---->made
</pre>
<blockquote type="cite">
<pre wrap="">to the sip .cpp code, it just won't work. Any help will be greatly
appreciated.
</pre>
</blockquote>
<pre wrap=""><!---->
It looks like your .sip file that wraps the sgRole() method is missing the
throw() part.
Phil
</pre>
</blockquote>
<br>
</body>
</html>