[Gdal-dev] Exception class(es) in SWIG C# wrapper
Richard Matsunaga
richard.matsunaga at waypointinfo.com
Mon Mar 5 17:06:51 EST 2007
If I remember correctly, many times in GDAL, a (C API) method will return
null when something could not happen, like opening a dataset.
In these cases, I would like to check for null and throw a GdalException or
OgrException, which contains the extended error message, up my call stack.
I could retrieve the error information and send that in any exception, like
an InvalidOperationException, but it's a little cleaner if we can
encapsulate the message details in new exception type.
It's something I would do in my own libraries, but it would be nice if
supported directly from the GDAL wrappers.
Cheers,
Richard
-----Original Message-----
From: Tamas Szekeres [mailto:szekerest at gmail.com]
Sent: March 5, 2007 4:29 PM
To: Richard Matsunaga
Cc: gdal-dev at lists.maptools.org
Subject: Re: [Gdal-dev] Exception class(es) in SWIG C# wrapper
Richard,
Currently the exception class you get should contain the same message string
as gdal.GetLastErrorMsg() retrieves. Is this the expected behaviour?
Best regards,
Tamas
2007/3/5, Richard Matsunaga <richard.matsunaga at waypointinfo.com>:
>
>
> Would it be appropriate or possible to insert a GDAL-specific
> exception class into the SWIG wrapper?
>
> This exception would fetch the extended error information from GDAL
> and automatically include this information in the exception message.
>
> I did this in the old hand-rolled GDAL/OGR wrapper. Other than the
> many constructors, it only needs to override the Message property.
>
>
> /// <summary>
> /// Gets the exception message. Includes the GDAL extended error
> message if available.
> /// </summary>
> public override string Message
> {
> get
> {
> return base.Message + "\n" + gdal.GetLastErrorMsg();
> }
> }
>
>
> Richard
>
>
> _______________________________________________
> 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