[geos-devel] GEOS Exceptions

Frank Warmerdam fwarmerdam at gmail.com
Mon Apr 18 11:16:45 EDT 2005


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 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



More information about the geos-devel mailing list