Loop iterator - example.txt
Dan
Dan_member at pathlink.com
Sat Apr 29 17:42:55 PDT 2006
>> In pseudo-code ...
>>
>> foreach (inout Customer cust; CustomerSet )
>> {
>> try {
>> cust.name = UI.CustName;
>> cust.address = UI.Address;
>> . . .
>> }
>> catch (BadUI e)
>> {
>> // Recover from the (rare) UI data error
>> . . .
>> retry; // Reprocess the same customer record.
>> }
>> }
>>
>
>Does that retry that instance, or retry the entire loop? Couldn't the
>semantics be either, given the appropriate condition?
Fortunately, it's not ambiguous. The try/catch is INSIDE the loop, so it will
continue the loop where it left off once the error is handled. If the try/catch
were outside the loop, it would run the whole loop over again.
I don't think it's really that difficult; and no, you can't separate the
try/catch and have one in and one out. That's a syntax error. If you throw
errors and catch them elsewhere, my understanding is that the program *should*
resume at the end of the try block once it's handled. Please correct me if I'm
wrong.
Also, unless some method is throwing an error, I highly recommend simply using
if or assert instead of try/catch. I *think* try/catch is traditionally done
through a very time consuming system fault mechanism, whereas if/assert are
simply a "short jcc" instruction.
More information about the Digitalmars-d
mailing list