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

Mateusz Loskot mateusz at loskot.net
Wed Nov 29 14:04:37 EST 2006


Ivan Lucena wrote:
> 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?

Ivan,

Yes, in such case your approach is OK.
Here, you can following one of exception safety rule in C++:
"if function can throw an exception, you have to assume it will throw".
So, if someone wraps GDAL adding features/handlers/whatever that can
throw C++ exception, and you're the user of such solution, then you can
assume that you have to catch these exceptions.
Without discussing if such throwing wrapper is designed well and safe or
not.

> 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.

Yes, I've supposed it's something like a wrapper.
I think it's a COM, am I right? :-)

> 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.

The most important thing here is that if an exception occurs,
everything that can be released by automatic destructor calls caused by
the exception will be released.
But if there is anything what can't be released that way, then
user/developer has to do it on his own, on exception.

Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the Gdal-dev mailing list