Why exceptions for error handling is so important

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Tue Jan 13 12:19:52 PST 2015


On 1/13/2015 3:01 AM, Russel Winder via Digitalmars-d wrote:
>
> On Mon, 2015-01-12 at 12:58 -0800, Walter Bright via Digitalmars-d wrote:
>> On 1/12/2015 11:30 AM, Russel Winder via Digitalmars-d wrote:
>>> Go has an interesting solution, key lookup in a map return a pair
>>> (result, ok), if lookup succeeded then result is the associated
>>> value, if ok is false then result is undefined. I quite like this.
>>
>>
>> That's just putting the responsibility of array bounds checking on
>> the caller.
>>
>> Would you want (result, ok) returned every time you indexed an
>> array? I sure
>> wouldn't. An associative array isn't conceptually any different.
>
> Why not?
>
> There is a fundamentally different approach to error handling
> depending on whether exceptions are integral cf. Python or anathema
> cf. Go and most functional programming languages. It is unreasonable
> to impose the idioms of one model onto another. And vice versa.

My point was more to the issue of how is array bounds checking done in those 
languages, and that aa checking should behave the same way when doing the same 
operations.


> arrays, sparse arrays and associative arrays are both very different
> and quite similar. The properties of the keys makes for very different
> approaches to algorithms, and possibly error handling of key lookup:
> contiguity of keys of an array is important.

In trying to make component programming work, I look for emphasizing 
similarities between containers rather than differences, in this case, what 
happens when presenting an invalid index.

Similarity in basic operations like that make it easy to swap in and out 
different containers without having to redo the rest of the code's interface to it.


More information about the Digitalmars-d mailing list