About use of specific error
Andreas Raab
andreas.raab at gmx.de
Thu Mar 2 17:55:18 UTC 2006
stéphane ducasse wrote:
>> Intervall >> remove: anElement
>> self error: 'elements cannot be removed from an Interval'
>>
>> What do you mean with "trapped more specifically"?
>
> Not for this one
> but
> IndexNotFoundError
> KeyNotFoundError
> SubscriptOutOfBoundsError
I have often wondered about the usefulness of such hierarchies. The way
I look at it, an exception hierarchy is useful if and only if one has a
need to handle the exceptions individually. And what's interesting here
is that in particular the above seem to be cases where nobody ever
handles them (and doesn't have the need to since there are always
variants that explicitly avoid the error condition like #at:ifAbsent:
#removeKey:ifAbsent: etc). Therefore I'd claim that if you have a case
where a client handles an exception by looking at the error text, then
by all means, make it a separate entity. But otherwise, don't make the
system more complex than it needs to be.
Cheers,
- Andreas
More information about the Squeak-dev
mailing list
|