[geos-devel] GEOS Exceptions

strk at refractions.net strk at refractions.net
Mon Apr 18 11:34:11 EDT 2005


On Mon, Apr 18, 2005 at 11:16:45AM -0400, Frank Warmerdam wrote:
> Folks,
> 
> I must confess I am not a particular advanced C++ programmer.  I
> tend to avoid use of C++ exceptions, so now I find myself in a situation
> where I am not quite sure what to do. 

I really think this is a GEOS bug, in that it throws by pointer
instead of by reference.
I'm somehow happy to know you faced this so maybe you'll support a
switch to a throw-by-reference-of-std::exception-derived, altought
it will be a big API break.

--strk;

> 
> I have the following code to parse a WKT string into a
> geos geometry. 
> 
>     try 
>     { 
>         geos::Geometry *geosGeometry = NULL;
>         geosGeometry = geosWktReader.read( oWKT );
>         return geosGeometry;
>     }
>     catch( geos::GEOSException &e )
>     {
>         CPLError( CE_Failure, CPLE_AppDefined,
>                   "GEOSException: %s", 
>                   e.toString().c_str() );
> 
>         return NULL;
>     }
> 
> The WKT in this case is invalid (a two point polygon) that looks
> like this:
> 
> POLYGON ((428909.103 4756578.350,681115.834 4980288.650))
> 
> Geos seems to throw an exception, but my catch does not seem 
> to be catching it.  I skimmed through the WKTReader code, and 
> I see it mostly throws ParseExceptions which are derived from
> GEOSException.  However, I suspect the exception that really
> gets thrown is at a lower validation level. 
> 
> Is anyone aware of exceptions that GEOS might throw in this
> case that are not derived from geos::GEOSException?  
> 
> Should my try/catch block catch all geos exceptions properly? 
> 
> Does anyone know an easy way to break in any exception
> as it is thrown in gdb? 
> 
> 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    | Geospatial Programmer for Rent
> _______________________________________________
> geos-devel mailing list
> geos-devel at geos.refractions.net
> http://geos.refractions.net/mailman/listinfo/geos-devel



More information about the geos-devel mailing list