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

Frank Warmerdam warmerdam at pobox.com
Tue Nov 28 12:06:56 EST 2006

Ivan Lucena wrote:
> Hi Matt, Martin, Frank, all,
>>> simply check error status after each GDAL call...
> That looks like that is the right thing to do. I just want to share the
> following piece of code with you guys where I am trying to use the same
> approach. I would like to know if I am going in the right direction, if
> you don't mind to take a quick look.
> // A C++ method:
> {
>     try
>     {
>         m_Dataset = (GDALDataset*) GDALOpen(pszFileName, GA_ReadOnly);
>         if (m_Dataset == NULL)
>         {
>             return E_FAIL;
>         }
>         return S_OK;
>     }
>     catch(...)
>     {
>         return E_FAIL;
>     }
> }
> I have debugged it a lot, forcing the error with invalid inputs (null
> pointer, invalid file name, invalid network address, etc.), and the
> result is that the caller of that method receives the exception nicely
> jumping to his own exception handler to do his own stuff as I would like
> it to do.


In theory GDALOpen() should never throw an exception, so I'm not sure
why the try block is needed around GDALOpen().  Are you encountering
circumstances where GDALOpen() does throw an exception?  Can you provide

Best regards,
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org

More information about the Gdal-dev mailing list