About use of specific error

stéphane ducasse ducasse at iam.unibe.ch
Thu Mar 2 13:11:15 UTC 2006


>> The consequence is that it can be tedious to capture only specific
>> error.
> Yes, it is often necessary to ask an exception for its message
> text to understand what happened. Checking the message texts
> is of course a bit risky, they can be changed at any time,
> they may be localized and so on.

Indeed
>
>> I was wondering what is the
>> general feeling about this state. In VW they have various exception
>> that can be trapped more specifically.
>>
>
> The collection relevant senders of error: are
> coded in these methods:
>
> Object>>errorSubscriptBounds:
> Object>>errorNonIntegerIndex
>
> Collection>>errorEmptyCollection
> Collection>>errorNotKeyed
> Dictionary>>errorKeyNotFound
> Dictionary>>errorValueNotFound
> SequenceableCollection>>checkedAt:
> SequenceableCollection>>errorFirstObject:
> SequenceableCollection>>errorLastObject:
> SequenceableCollection>>errorOutOfBounds
> Set>>add:
>
> SequenceableCollection>>with:do:
> SequenceableCollection>>with:collect:
>
> Using specialized exceptions is attractive, but
> it is not easy to find a good exception
> hierarchy. What do you think about this
> hierarchy for collection related errors?
>
> Error
>   CollectionAccessError
>     IndexOutOfBoundsError
>     KeyNotFoundError
>     EmptyCollectionError
>
> This would give you the possibility to write
> handler like:
>
>  [collection at: item]
>    on: CollectionAccessError
>    do:
>      [:exception |
>         " exception class tells you more about
>           the nature of the error "
>      ].
>
>
> Apart form the problem of finding a good
> hierarchy,

Which is not easy

> we have to ask ourselves how many
> exception classes we want to have. For
> teaching purposes, it is a good idea to
> implement a stack with a FullStackError
> and an EmptyStackError and a common
> superclass  StackError, but is it really
> necessary to have tenths or hundreds of
> specialized error classes in a general purpose
> image?

Exactly. I would be against it.
I think that exception are often a Java plague :)
Still I was thinking that thinking about that could be interesting.

> I think I would like to have specialized exceptions
> for collections, but perhaps this is something one
> should try to find out whether there are hidden
> disadvantages.

Thanks for the email because it shows that we are in sync.

Stef

>
> Greetings,
> Boris
>




More information about the Squeak-dev mailing list