-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
consolidate exception stuff for Python so both GDAL and OGR can use it (
https://trac.osgeo.org/gdal/ticket/1638) git-svn-id: https://svn.osgeo.org/gdal/trunk@11517 f0d54148-0727-0410-94bb-9a71ac55c965
- Loading branch information
Showing
3 changed files
with
45 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* This was the cpl_exceptions.i code. But since python is the only one | ||
* different (should support old method as well as new one) | ||
* it was moved into this file. | ||
*/ | ||
%{ | ||
int bUseExceptions=0; | ||
|
||
void VeryQuiteErrorHandler(CPLErr eclass, int code, const char *msg ) { | ||
/* If the error class is CE_Fatal, we want to have a message issued | ||
because the CPL support code does an abort() before any exception | ||
can be generated */ | ||
if (eclass == CE_Fatal ) { | ||
CPLDefaultErrorHandler(eclass, code, msg ); | ||
} | ||
} | ||
%} | ||
|
||
%inline %{ | ||
void UseExceptions() { | ||
bUseExceptions = 1; | ||
CPLSetErrorHandler( (CPLErrorHandler) VeryQuiteErrorHandler ); | ||
} | ||
|
||
void DontUseExceptions() { | ||
bUseExceptions = 0; | ||
CPLSetErrorHandler( CPLDefaultErrorHandler ); | ||
} | ||
%} | ||
|
||
%include exception.i | ||
|
||
%exception { | ||
|
||
$action | ||
if ( bUseExceptions ) { | ||
CPLErr eclass = CPLGetLastErrorType(); | ||
if ( eclass == CE_Failure || eclass == CE_Fatal ) { | ||
SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() ); | ||
} | ||
} | ||
} |