diff --git a/swig/include/gdal_array.i b/swig/include/gdal_array.i index 21c32f545b04..156079bf6124 100644 --- a/swig/include/gdal_array.i +++ b/swig/include/gdal_array.i @@ -66,27 +66,6 @@ typedef int GDALRIOResampleAlg; %include "python_strings.i" -%{ -#include "cpl_conv.h" -%} - -%inline %{ -// Note: copied&pasted from python_exceptions.i -static void _StoreLastException() -{ - const char* pszLastErrorMessage = - CPLGetThreadLocalConfigOption("__last_error_message", NULL); - const char* pszLastErrorCode = - CPLGetThreadLocalConfigOption("__last_error_code", NULL); - if( pszLastErrorMessage != NULL && pszLastErrorCode != NULL ) - { - CPLErrorSetState( CE_Failure, - static_cast(atoi(pszLastErrorCode)), - pszLastErrorMessage); - } -} -%} - %{ #include #include "gdal_priv.h" @@ -2087,7 +2066,6 @@ def GDALTypeCodeToNumericTypeCode(gdal_code): def _RaiseException(): if gdal.GetUseExceptions(): - _StoreLastException() raise RuntimeError(gdal.GetLastErrorMsg()) def LoadFile(filename, xoff=0, yoff=0, xsize=None, ysize=None, diff --git a/swig/include/python/gdal_python.i b/swig/include/python/gdal_python.i index 448e0ec0ba1a..3edc88f562a2 100644 --- a/swig/include/python/gdal_python.i +++ b/swig/include/python/gdal_python.i @@ -12,6 +12,7 @@ if ( GDALGetDriverCount() == 0 ) { GDALAllRegister(); } + UseExceptions(); %} %{ diff --git a/swig/include/python/gnm_python.i b/swig/include/python/gnm_python.i index b0c2f01a70db..1ade9666f5e8 100644 --- a/swig/include/python/gnm_python.i +++ b/swig/include/python/gnm_python.i @@ -12,6 +12,7 @@ if ( OGRGetDriverCount() == 0 ) { OGRRegisterAll(); } + UseExceptions(); %} #endif diff --git a/swig/include/python/ogr_python.i b/swig/include/python/ogr_python.i index f2adbd1c37c3..632621ce6a67 100644 --- a/swig/include/python/ogr_python.i +++ b/swig/include/python/ogr_python.i @@ -12,6 +12,7 @@ if ( OGRGetDriverCount() == 0 ) { OGRRegisterAll(); } + UseExceptions(); %} #endif diff --git a/swig/include/python/osr_python.i b/swig/include/python/osr_python.i index eb77314dea4d..8d0a8efeffab 100644 --- a/swig/include/python/osr_python.i +++ b/swig/include/python/osr_python.i @@ -6,6 +6,10 @@ %feature("autodoc"); +%init %{ + UseExceptions(); +%} + #ifndef FROM_GDAL_I %{ #define MODULE_NAME "osr"