Skip to content

Commit

Permalink
consolidate exception stuff for Python so both GDAL and OGR can use it (
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed May 14, 2007
1 parent b7a975c commit 66e0101
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
42 changes: 1 addition & 41 deletions gdal/swig/include/python/gdal_python.i
Original file line number Diff line number Diff line change
Expand Up @@ -33,49 +33,9 @@
}
%}

/*
* 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() );
}
}
}

%include "python_exceptions.i"

%extend GDAL_GCP {
%pythoncode {
Expand Down
2 changes: 2 additions & 0 deletions gdal/swig/include/python/ogr_python.i
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
%rename (SetGenerate_DB2_V72_BYTE_ORDER) OGRSetGenerate_DB2_V72_BYTE_ORDER;
%rename (RegisterAll) OGRRegisterAll();

%include "python_exceptions.i"

%extend OGRDataSourceShadow {
%pythoncode {
def Destroy(self):
Expand Down
42 changes: 42 additions & 0 deletions gdal/swig/include/python/python_exceptions.i
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() );
}
}
}

0 comments on commit 66e0101

Please sign in to comment.