[gdal-dev] Throwing exceptions in GDAL Error Handler

Even Rouault even.rouault at spatialys.com
Sat Dec 4 15:59:52 PST 2021


You shouldn't throw C++ exceptions, as this is a callback of the C API. 
This will cause all sort of issues, most of the time memory leaks, etc.

Le 05/12/2021 à 00:49, Simon Eves a écrit :
> We have a custom Error Handler callback and for a while now it was 
> configured to throw an exception if the class was Failure or higher.
>
> Unfortunately, we have found that this causes havoc with OpenEx() 
> because the file management state is left bad (e.g. the anti-recursion 
> stuff) and GDAL will believe the file is open when it isn't, and other 
> such hilarity.
>
> We have changed this to disable and re-enable the exception throw (and 
> just log the error) either side of an OpenEx() but I am concerned that 
> there are perhaps other situations where throwing may cause similar 
> issues.
>
> The docs for CPLSetErrorHandler() don't explicitly say anything about 
> not throwing in the callback.
>
> Please advise.
>
> SE
>
> -- 
> <http://www.omnisci.com/>
> 	
> Simon Eves
> Senior Graphics Engineer, Rendering Group
> 100 Montgomery St (5th Floor), San Francisco, CA 94104, USA
>
>
> 	
> Email: simon.eves at omnisci.com <mailto:simon.eves at omnisci.com> | Cell: 
> +1 (415) 902-1996
>
>
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev

-- 
http://www.spatialys.com
My software is free, but my time generally not.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20211205/309b1c16/attachment.html>


More information about the gdal-dev mailing list