[gdal-dev] Catch a GDALOpen exception

Mateusz Loskot mateusz at loskot.net
Wed Apr 6 15:34:42 EDT 2011


Even Rouault wrote:
> Le mercredi 06 avril 2011 18:09:42, Howard Butler a écrit :
>> You need to implement your own error handler if you want GDAL to throw
>> exceptions when it can open something.
>
> I would recommand *against* doing that. Throwing exceptions from the GDAL
> error handler can lead to memory leaks and/or file descriptor leaks
> because the GDAL drivers will not be able to release memory/file
> descriptors

Even,

This is interesting. Could you give example?
How is checking if GDALOpen returned NULL and prematurely exiting
different to throwing exception?

It should be possible to react on GDAL errors and throw exception
as long as certain cleanup is performed.

> (there's no guarantee that the GDAL error is emitted
> before the cleanup of ressources has been done).

What error emission you mean? Returning NULL? Call to abort()?

I have written code intensively throwing exceptions around GDAL,
even CPLErr is used one of exception type. Code is well-tested
and I haven't noticed problems.

Hobu's solution might be incomplete, but gives rough idea which is valid
if used properly. In any case, details are needed to be able to judge.

Best regards,
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the gdal-dev mailing list