Skip to content

Commit

Permalink
Add SIP_THROW annotation
Browse files Browse the repository at this point in the history
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
declaration:

    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 0f78277
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/sipify.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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
# https://regex101.com/r/uvCt4M/4
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgis_sip.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@
*/
#define SIP_VIRTUALERRORHANDLER(name)

/*
* 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
*/
Expand Down

0 comments on commit 0f78277

Please sign in to comment.