Skip to content
Browse files
Add SIP_THROW annotation
SIP uses the deprecated throw(...) annotation in order to determine
which exceptions may be thrown by c++ code. Without these, only
a generic unknown exception is throw, which is of limited value
to Python code (losing any valuable message and exception type).

So we add a new SIP_THROW macro, which can be added to method's

    bool doSomething() SIP_THROW( QgsCsException );

This is ignored outside of sipify, so we don't actually use
the deprecated c++ throw annotations, but sipify picks it up
and adds the appropriate change to the sip definition for
the method:

   bool doSomething() throw( QgsCsException );

This means that calling the method from Python will raise
the QgsCsException instead of a generic exception.
  • Loading branch information
nyalldawson committed May 15, 2018
1 parent cd34da8 commit 0f78277a597f72fa65648c1cb4aa0660da77b9e1
Showing with 8 additions and 0 deletions.
  1. +1 −0 scripts/
  2. +7 −0 src/core/qgis_sip.h
@@ -344,6 +344,7 @@ sub fix_annotations {

$line =~ s/SIP_PYNAME\(\s*(\w+)\s*\)/\/PyName=$1\//;
$line =~ s/SIP_VIRTUALERRORHANDLER\(\s*(\w+)\s*\)/\/VirtualErrorHandler=$1\//;
$line =~ s/SIP_THROW\(\s*(\w+)\s*\)/throw\( $1 \)/;

# combine multiple annotations
@@ -169,6 +169,13 @@

* Throw - adds deprecated c++ throw calls for sip. Required for sip to add appropriate
* try/catch blocks around call and catch the correct exception, otherwise only
* unknown generic exceptions are available for Python code.
#define SIP_THROW(name)

* Will insert a `%End` directive in sip files

0 comments on commit 0f78277

Please sign in to comment.