[PyQt] sip: extend exception support

Phil Thompson phil at riverbankcomputing.com
Mon Aug 27 13:34:10 BST 2012


On Sun, 26 Aug 2012 22:22:40 +0200, Mathias.Born at gmx.de wrote:
> On 26.08.2012, 16:07:52 Phil Thompson wrote:
>> On Sun, 26 Aug 2012 14:30:32 +0200, Mathias.Born at gmx.de wrote:
>>> On 26.08.2012, 16:46:24 Phil Thompson wrote:
>>>> On Wed, 15 Aug 2012 15:54:11 +0200, Mathias.Born at gmx.de wrote:
>>>>> ...
> 
>> Should all be fixed in current hg and tonight's snapshot.
> 
>> Thanks,
>> Phil
> 
> 
> Ok, I pulled from the hg and could build everything. Quite nifty.
> One can now use class instances implemented in python just like
> normal C++ without any additional worries.
> 
> One issue though. Discussions like
> 
> http://www.boost.org/community/error_handling.html
> 
> suggest that SIPPyException should be derived from std::exception.
> My original suggestion was a bit short-sighted. It would be even
> better to let the user define his own exception class.
> 
> I'm using sip to embed python code into a Qt/C++ program. Every
> exception is reported to the user via a message box:
> 
> catch(std::exception const& exc)
> {
>   QMessageBox(QMessageBox::Critical, "Error", exc.what(),
>   QMessageBox::Ok).exec();
> }
> 
> With SIPPyException the way it is, I need to add another exception
> handler everywhere:
> 
> catch(SIPPyException const&)
> {
>   QMessageBox(QMessageBox::Critical, "Error", pythonExceptionToText(),
>   QMessageBox::Ok).exec();
> }
> 
> If I could provide a function to call instead of just doing
> "throw SIPPyException()", I could throw an exception there myself
> as I see fit. For example, there could be a directive
> 
> %MethodErrorHandlerCode
>   throw std::runtime_error(pythonExceptionToText());
> %End
> 
> which would follow the %Module directive to define the body of an
> error handler function which is called instead of "throw
SIPPyException()".
> 
> Best Regards,
> Mathias

In current hg...

%VirtualErrorCode is a new sub-directive of the %Module directive.

all_throw_cpp_exception replaced by all_use_VirtualErrorCode.

/ThrowsCppException/ replaced by /UsesVirtualErrorCode/.

/NoThrowsCppException/ replaced by /NoUsesVirtualErrorCode/.

Removed SIPPyException.

Phil


More information about the PyQt mailing list