Change the name of ArrayBoundsException in druntime
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Wed Oct 22 09:24:40 PDT 2008
Denis Koroskin wrote:
> On Wed, 22 Oct 2008 19:06:24 +0400, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>
>> Jarrett Billingsley wrote:
>>> On Wed, Oct 22, 2008 at 6:49 AM, Jacob Carlborg <doobnet at gmail.com>
>>> wrote:
>>>> I think the name ArrayBoundsException should be changed to a more
>>>> general
>>>> name like BoundsException, OutOfBoundsException or
>>>> IndexOutOfBoundsException. Then you can use the exception in every
>>>> class
>>>> that have some sort of index operation and not just for an array/array
>>>> class.
>>>>
>>> 2nded.
>>
>> I agree. In fact I wanted to ask you all the following question. What do
>> you think about the current exception hierarchy in phobos? I think it is
>> terrible. Each module in std you open, the first piece of code to be
>> seen is the "class ThisModuleNameException" definition. In many (most?)
>> cases the module-specific exception does absolutely nothing in addition
>> to its base class. The putative reader (including me) tends to scroll
>> non-critically over that passage without even blinking, mumbling in a
>> trance - of course, yes, each module should define at least one
>> exception type.
>>
>> Until one day when you stop scrolling and say, wait a minute. This all
>> is repetition. And there are alternatives to catching by type - you
>> can catch the base type and consult a field. And in fact I don't
>> remember seeing code that depends on exceptions thrown from different
>> modules having different types. There's something wrong here!
>>
>> I think most exception classes in phobos should be yanked if it's
>> possible for their functionality (often nil) to be moved in the
>> Exception base class. The module name should be a member. If someone
>> needs to deal with an exception thrown from a specific module, they
>> can always inspect the field. We don't need a huge hierarchy for that.
>>
>>
>> Andrei
>
> There is sometimes a need to differentiate between a specific exception
> and a generic one, even though the former or does nothing.
>
> typedef Exception MyException; // might be a good compromise
>
> try {
> throw new MyException("reason");
> } catch (MyException e) {
> // catch concrete exception
> } catch (Exception e) {
> // catch generic exception
> }
>
> This code currently doesn't work, because compiler thinks that
> MyException and Exception are of the same type, which is wrong -
> MyException is kind of a subclass of Exception, as the following sample
> shows:
>
> typedef Exception MyException;
>
> void main()
> {
> MyException me = new MyException("reason");
> Exception e = me; // implicit downcast
> me = e; // doesn't work, it is an upcast
> Object o = me; // ICE! :)
> }
>
> Could anyone put it into bugzilla? (I have no access to HTTP currently :()
I'd discussed that with Walter. He said that making typedefs
full-fledged classes would be technically difficult.
Andrei
More information about the Digitalmars-d
mailing list