[Gdal-dev] SWIG Exceptions for C# Bindings

Tamas Szekeres szekerest at gmail.com
Fri Mar 16 10:34:12 EDT 2007


It depends on the implementation in the gdal core whether the CPLError
is invoked or not. Generally if we can retrieve the error by calling
CPLGetLastErrorType() the error will be propagated to C# as an
exception.
As far as I can see the various providers are not calling CPLError in
DataSource.GetLayerByIndex. Here is a common example of it:

OGRLayer *OGRPGDataSource::GetLayer( int iLayer )
{
    if( iLayer < 0 || iLayer >= nLayers )
        return NULL;
    else
        return papoLayers[iLayer];
}

Therefore you should always check the return value in this case.

Best regards,

Tamas


2007/3/16, Simon Perkins <sy at perkins.net>:
> Can someone remind me how error reporting works with the GDAL and OGR C#
> bindings? Do errors typically throw exceptions, or return status codes,
> or nulls, or both? There seems to be code to throw exceptions in most of
> the method definitions, but the code in swig/csharp/apps often appears
> to be checking for return null values instead. Which is correct?
>
> For instance, if OGR.DataSource.GetLayerByIndex() is invoked with an
> invalid index, or if something else goes wrong, do we always/sometimes
> get an exception or do we just get a null back? Is there a general policy?
>
> Cheers,
>
> Simon
>
> _______________________________________________
> Gdal-dev mailing list
> Gdal-dev at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/gdal-dev
>



More information about the Gdal-dev mailing list