[Gdal-dev] GDAL CPLError and C++ Exceptions

Chapman, Martin MChapman at sanz.com
Mon Nov 27 18:30:07 EST 2006


One more thing.  A gdal error is either because the gdal function
returned an error code of type OGRErr, or a function returned NULL.
Handle each case as follows:

// example of a GDALSpatialReference function that returns an error code
OGRErr err = spatialRef.exportToWkt(&pszWks);

// or something that returns null
pDataset = pDriver->Create((const char*) sConnectString.c_str(), nWidth,
nHeight, (int) pBands->size(), eDataType, papszOptions);
if (!pDataset) 
	throw (char*) CPLGetLastErrorMsg();

Martin Chapman
Software Developer
http://www.earthwhere.com
W - 303.495.6326
C  - 303.898.0397

-----Original Message-----
From: gdal-dev-bounces at lists.maptools.org
[mailto:gdal-dev-bounces at lists.maptools.org] On Behalf Of Matt Hanson
Sent: Monday, November 27, 2006 3:25 PM
To: Gdal-dev at lists.maptools.org
Subject: [Gdal-dev] GDAL CPLError and C++ Exceptions

Hi, I recently got hung up on tracking down an GDAL error because I'm
not handling errors from CPLError.   I'd like to be able to handle those
errors and create C++ Exceptions but I'm not clear on how to do so.
Anyone have any code examples for how I might turn CPLErrors into
Exceptions?   It looks like I should probably set the error handler, but
what should that function look like?   Would it simply examine the
contents of the GDAL Error number and message and decide to throw or not
throw an exception? (which would then be presumably caught in a user's
application).
 
Thanks !
 
matt

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




More information about the Gdal-dev mailing list