[Liblas-devel] Throwing out_of_range exceptions on read

Mateusz Loskot mateusz at loskot.net
Tue Apr 29 12:32:53 EDT 2008


Howard Butler wrote:
> On Apr 28, 2008, at 9:34 PM, Mateusz Loskot wrote:
>>
>> Another point is that in most cases LASWriter throws if its internal 
>> state is invalid, and it does not make sense to continue calling writer.
> 
> If this is true, a client must do try ... catch to be robust 
> regardless.  I agree the simple boolean has a cleaner form, but if 
> WritePoint is already expected to throw exceptions, we might as well 
> take advantage of it.

Hobu,

Yes, it is true that the writer throws, but it does not require user to 
nest try-catch block inside a loop.
Currently, user is free to decide to catch critical errors of writer 
state on levels up (even only in the main function***), but if exception 
is thrown as validation result, then try-catch is required to be nested 
in writing loop.

*** example

int main()
{
   try
   {
      // LASWriter called here, throws if its state is invalid
   }
   catch (std::exception e)
   {
      std::cout << "Writing failure. Aborting!\n";
   }

   return 0;
}

This is a subtle but crucial difference.

>> But if a point is invalid, state of writer object is OK and we can 
>> safely continue using writer.
> 
> Maybe we need two validation methods, one boolean and one that throws.

I don't think so.

Simply, the validation is just a regular node in decision tree and
it influences execution flow. So, if-statement is the right choice to 
check the decision and direct the execution.
Exceptions should not [1] be used for flow control.

[1] http://c2.com/cgi/wiki?DontUseExceptionsForFlowControl


Greetings
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the Liblas-devel mailing list