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

Matt Hanson mhanson at photon.com
Tue Nov 28 10:17:13 EST 2006

Ok thanks, that answers my question.   I was thinking I could write my own error handlers but sounds like that is not a good idea and I just need to simply check error status after each GDAL call.  Martin - thanks for the tips in the other posts.


From: Frank Warmerdam [mailto:warmerdam at pobox.com]
Sent: Mon 11/27/2006 8:35 PM
To: Matt Hanson
Cc: Gdal-dev at lists.maptools.org
Subject: Re: [Gdal-dev] GDAL CPLError and C++ Exceptions

Matt Hanson wrote:
> 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).


I just wanted to add a couple things:

  o You can also install your own error handlers to be called by CPLError().
    You can find some more information about this at:


  o However, you should generally *not* throw exceptions from within such
    an error handler, as GDAL does not guarantee proper cleanup in the face
    of an exception deep in the internals.  At the very least you are likely
    to see memory leaks, and quite possible data structures could be left
    in an improper state.  If you want to throw exceptions, it is best to do
    it after the GDAL calls, as shown in the other email.

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    | President OSGeo, http://osgeo.org <http://osgeo.org/> 

More information about the Gdal-dev mailing list