[gdal-dev] [gdal Python] Exceptions not reset correctly ifgdal.UseExceptions() is used

Jason Roberts jason.roberts at duke.edu
Fri Jun 19 09:46:38 EDT 2009


As a Python programmer that uses GDAL and OGR, I second this opinion.

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. 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.

Best,
Jason

-----Original Message-----
From: gdal-dev-bounces at lists.osgeo.org [mailto:gdal-dev-bounces at lists.osgeo.org] On Behalf Of Antonio Valentino
Sent: Friday, June 19, 2009 2:42 AM
To: gdal-dev at lists.osgeo.org
Subject: Re: [gdal-dev] [gdal Python] Exceptions not reset correctly ifgdal.UseExceptions() is used

Even,
my opinion is that if all info are attached to the python exception then it 
should not matter if the error status is reset or not.

Anyway I can't figure out why an exception is raised if the called function 
that doesn't generete any error.

best regards

--
Antonio VALENTINO
System Engineer
INNOVA Consorzio per l'Informatica e la Telematica s.r.l.
Z.I. La Martella - C.da Chiatamura - Lotto 188 - 75100 Matera (MT) Italy
Tel.: +39 0835 1852131, +39 0835 307760 (+39 0835 309180)
Fax: +39 0835 264705
Email: valentino at consorzio-innova.it
Home Page: www.consorzio-innova.com

*ATTENZIONE*: le informazioni contenute in questo messaggio sono da 
considerarsi confidenziali ed il loro utilizzo e' riservato unicamente al 
destinatario sopra indicato. Chi dovesse ricevere questo messaggio per 
errore e' tenuto ad informare il mittente ed a rimuoverlo definitivamente da 
ogni supporto elettronico o cartaceo.

*WARNING*: This message contains confidential and/or proprietary information 
which may be subject to privilege or immunity and which is intended for use 
of its addressee only. Should you receive this message in error, you are 
kindly requested to inform the sender and to definitively remove it from any 
paper or electronic format.


----- Original Message ----- 
From: "Even Rouault" <even.rouault at mines-paris.org>
To: <gdal-dev at lists.osgeo.org>
Cc: "Luca Fasano" <lucafasano at interfree.it>
Sent: Thursday, June 18, 2009 11:03 PM
Subject: Re: [gdal-dev] [gdal Python] Exceptions not reset correctly 
ifgdal.UseExceptions() is used


Luca,

(This behaviour is identical in trunk too)

we could probably reset the error state after issuing the exception, but 
that
would prevent code from getting the error message if they call
gdal.GetLastErrorMsg() afterwards. But I don't think this would be a 
problem.
We should probably also call ErrorReset() in gdal.UseExceptions() so that
previous errors don't cause unexpected exceptions to be thrown.

Howard ?

Le Thursday 18 June 2009 10:09:27 Luca Fasano, vous avez écrit :
> Hi all,
> I suspect there is a bug in gdal.UseExceptions() in python binding.
> I noticed that if a RuntimeError has been generated, following gdal
> instructions *raise the same exception*.
> It seems that a gdal.ErrorReset() is necessary to reset it.
> An example with ipython:
>
> In [2]: from osgeo import gdal
>
> In [3]: gdal.UseExceptions()
>
> In [4]: dataset = gdal.Open('./filename.wrongformat')
> ---------------------------------------------------------------------------
> RuntimeError                              Traceback (most recent call
> last)
>
> /home/fasano/Desktop/test/<ipython console> in <module>()
>
> RuntimeError: `./filename.wrongformat' not recognised as a supported
> file format.
>
>
> In [5]: gdal.GetCacheMax()
> ---------------------------------------------------------------------------
> RuntimeError                              Traceback (most recent call
> last)
>
> /home/fasano/Desktop/test/<ipython console> in <module>()
>
> RuntimeError: `./filename.wrongformat' not recognised as a supported
> file format.
>
>
> In [6]: gdal.ErrorReset()
>
> In [7]: gdal.GetCacheMax()
> Out[7]: 41943040
>
>
> (My gdal version is 1.5.4)
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev


_______________________________________________
gdal-dev mailing list
gdal-dev at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev 

_______________________________________________
gdal-dev mailing list
gdal-dev at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev



More information about the gdal-dev mailing list