[Gdal-dev] GDAL CPLError and C++ Exceptions
Frank Warmerdam
warmerdam at pobox.com
Mon Nov 27 20:35:26 EST 2006
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).
Matt,
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:
http://www.gdal.org/cpl__error_8h.html
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
More information about the Gdal-dev
mailing list