The Right Approach to Exceptions

Jacob Carlborg doob at me.com
Tue Feb 21 12:05:40 PST 2012


On 2012-02-21 19:33, Juan Manuel Cabo wrote:
>> That because you can't (shouldn't) push up implementations specific to a given subclass. Why don't we only have one
>> class, Object, and add a Variant[string] there.
>>
>> Do you see how stupid that is.
>
> As stupid as any database API which returns result items as Variant[string] or
> string[string], but it works. (the sad part is that one has to rely a bit on
> convention, but convention can be standardized (string constants) and measures
> taken when deviated so that it is done gracefuly).

That's because we are limited by the database API. If you created a new 
database from scratch, completely written in D, perhaps even object 
oriented, you could return the correct object form the beginning.

> Do you have an alternative solution that allows to extend an exception
> object with extra information, while keeping it the same class?

No, but that's what subclasses are used for.

> So if one removes the bad reasons to create new Exception types, then the
> ones that DO get created are solid, standard, reusable, and can withstand
> the test of time. Because they would be open for extension but closed for
> source code modification.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list