Opened 21 years ago

Last modified 17 years ago

#288 closed enhancement (fixed)

gdal python bindings should raise exception on error conditions

Reported by: alessandro_amici@… Owned by: warmerdam
Priority: high Milestone:
Component: default Version: unspecified
Severity: minor Keywords:
Cc:

Description

hi,

I am one using mainly the python bindings and I'd like to point out
one of my wishlist items:

gdal.Open(filename) returns None in case of failure. But, raising an IOError
exception wuold be more consistent with the python style. Similarly for
other error conditions (i.e. GetDriverByName(), Driver.Create(), etc).
I understand this wuold be a significant interface change, that you might
be reluctant to implement. But please note that I end up doing:

	im = gdal.Open(filename)
	if im is None:
		raise IOError, 'Could not open "$s"' % filename

quite often anyhow. Moreover, right now the gdal related code ends up being
obfuscated by numerous error-handling paths needed.
IMHO most of that could be avoided with the use of exceptions.

thanks,
alessandro

Change History (2)

comment:1 by neteler@…, 21 years ago

Frank

you were searching for DTED with NULL data.
Attached DTED1 could potentially contain NULL values
It's in southern Italy covering Naples and the sea.

gdalinfo -mm N2.DT1
Driver: DTED/DTED Elevation Raster
Size is 1201, 1201
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433]]
Origin = (13.999583,41.000417)
Pixel Size = (0.000833,-0.000833)
Metadata:
  DTED_VerticalAccuracy=0030
  DTED_SecurityCode=U
  DTED_Producer=IT-CIGA
  DTED_CompilationDate=8805
Corner Coordinates:
Upper Left  (  13.9995833,  41.0004167) ( 13d59'58.50"E, 41d 0'1.50"N)
Lower Left  (  13.9995833,  39.9995833) ( 13d59'58.50"E, 39d59'58.50"N)
Upper Right (  15.0004167,  41.0004167) ( 15d 0'1.50"E, 41d 0'1.50"N)
Lower Right (  15.0004167,  39.9995833) ( 15d 0'1.50"E, 39d59'58.50"N)
Center      (  14.5000000,  40.5000000) ( 14d30'0.00"E, 40d30'0.00"N)
Band 1 Block=1x1201 Type=Int16, ColorInterp=Undefined
    Computed Min/Max=0.000,1783.000

Best regards

 Markus

comment:2 by hobu, 17 years ago

I am closing this one for now.  The next-gen SWIG bindings optionally support exceptions.  You need to do gdal.UseExceptions() at the top of your script and when OGR or GDAL has an error, it will throw with the appropriate message.
Note: See TracTickets for help on using tickets.