[gdal-dev] [gdal Python] Exceptions not reset correctly
ifgdal.UseExceptions() is used
Frank Warmerdam
warmerdam at pobox.com
Fri Jun 19 10:20:33 EDT 2009
Antonio Valentino wrote:
> Anyway I can't figure out why an exception is raised if the called
> function that doesn't generete any error.
Antonio,
Sometimes a GDAL function calls a lower level function that posts an error,
but that the higher level API ignores without even realizing it occured -
often because the error was insignificant in the context of use. In
situations like this the error can remain posted in the error cache and
trigger an exception when things return to the python api.
The fix is to identify these situations, and ensure that the calling
function calls ErrorReset for errors that should be ignored.
Jason Roberts wrote:
>
> The most "Pythonic" interface would be one in which all GDAL/OGR
> functions raise exceptions when they fail. This would be enabled
> by default, and the UseExceptions and ErrorReset methods would not
> be exposed at all. This approach is consistent with the rest of
> Python's libraries, and it is what Python programmers are used
> to. If this cannot be done (perhaps because people are too used
> to the existing interface that does not raise exceptions by default),
> then a Python program should be able to call UseExceptions once at
> the beginning to enable this behavior.
This is the intended approach with UseExceptions() being off by default
to protect compatability of operation for existing python scripts. A
script with UseExceptions() on should
> There is no reason why a Python program should ever need to call
> ErrorReset. Python programmers are already used to catching exceptions
> and the idea of polling for errors and resetting error states is unusual
> to them.
I agree, in UseExceptions() mode. I'm not clear why the Python bindings
over the C API do not call ErrorReset() before any call into the C API.
I thought they did. I think Howard is going to investigate a bit.
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent
More information about the gdal-dev
mailing list