[geos-devel] Exception Issues

Martin Davis mbdavis at VividSolutions.com
Tue May 27 11:53:01 EDT 2003


> There is some confusion as to how to handle
> C++ exceptions, which are NOT the same thing as JAVA exceptions

<rant>
Norman, you could well be right here, if you are talking about the precise semantics of the C++ VS Java execution model.  The Java execution semantics are pretty well defined (witness the high level of portability of code between different JVMs).  C++ semantics are MUCH less well defined (witness the current problems with exceptions to do with the compiler?  the linker?  the dynamic loader?  - all these tools vary greatly between different implementations, in undocumented and unpredictable ways)   
</rant>

That said, it's my belief that both C++ and Java exceptions are designed to do pretty much the same thing - allow transfer of control and error information up through the execution stack with minimal impact on code which does not handle the error.  In C++ this is trickier than in Java, since you need to manually clean up memory resources as you unwind the stack.  (The <autoptr> thingie in STL is supposed to help with this).  But I think we can accomplish this with some reasonable diligence.

> That said now that we have all of the PostGIS GEOS interaction
> in a C++ not a C library we should be able to handle any "standard"
> exception thrown by the GEOS code by including it within an 
> appropriate  try block

As I understand it, the problem we have is such that we can't simply fix it by wrapping each GEOS function in a try block.  (In fact, I think this was proposed and tried when we first encountered the problem). The problem is deeper than that - it goes back to what I said earlier about unexpected and widely varying semantics of the C++ execution model.  In this case, the compiler or linker being used handle a throw as an abort - which is probably not be considered as adherence to the generally accepted model of C++ execution.

Martin Davis, Senior Technical Architect
Vivid Solutions Inc.
Suite #1A-2328 Government Street   Victoria, B.C.   V8T 5G5
Phone: (250) 385 6040    Fax: (250) 385 6046
EMail: mbdavis at vividsolutions.com  Web: www.vividsolutions.com

> 



More information about the geos-devel mailing list