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

Ivan Lucena ILucena at clarku.edu
Tue Nov 28 16:30:48 EST 2006

Matt, Frank,

Your both comments are great, thank.

I understand that try/catch is useless around GDAL API calls. The point
is well taken. But if there is a possibility that somebody could place a
GDALnn.DLL in the system and in that GDALL built there is a custom error
handling that *does* throws exception, then I think that I should keep
my extra-precautious try/catch. Is it possible? And what is worth?

Matt, I didn't mention that but I am developing a wrapper, so in this
case I am expecting that the application developers will take some of
the release-resource responsibility to themselves. But I understand your
point. If I really needed to release any *direct dependent resources*
that should be done before "return E_FAIL". The caller will receive it
as an exception.

Thank you very much that was very helpful.


-----Original Message-----
From: gdal-dev-bounces at lists.maptools.org
[mailto:gdal-dev-bounces at lists.maptools.org] On Behalf Of Mateusz Loskot
Sent: Tuesday, November 28, 2006 12:17 PM
To: gdal
Subject: Re: [Gdal-dev] GDAL CPLError and C++ Exceptions

I'd like to share my comments:

1. GDAL calls do not throw C++ exceptions.
2. GDAL calls do not use C++ Standard Library features throwing
exceptions. OK, std::string class is used.
3. Even if GDALOpen will throw anything, your version is not exception
safe, unless
3.1 GDALOpen promises to release all resources on throw
3.2 You call GDALClose on catch, before return E_FAIL

More information about the Gdal-dev mailing list