The Right Approach to Exceptions

Nick Sabalausky a at a.a
Mon Feb 20 11:12:46 PST 2012


"Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message 
news:jhtss8$12mq$3 at digitalmars.com...
> On 2/20/12 10:16 AM, Nick Sabalausky wrote:
>> "Andrei Alexandrescu"<SeeWebsiteForEmail at erdani.org>  wrote in message
>> news:jhtq31$u8q$1 at digitalmars.com...
>>>
>>> Again, I think this thread clarified we need the "Variant[string] info;"
>>> member however we define the hierarchy.
>>>
>>
>> I disagree. I don't see a need for that.
>
> How would we address custom formatting of e.g. error messages?
>

Maybe I've misunderstood your intent for this "Variant[string] info;" My 
understanding is that, for example, you want to replace this:

----------------------------------------------------
class Exception {}
class FooException
{
    string fooName;
    int fooID;
    bool didBarOccur;

    this(string fooName, int fooID, bool didBarOccur)
    {
        this.fooName = fooName;
        this.fooID= fooID;
        this.didBarOccur= didBarOccur;
    }
}
----------------------------------------------------

With this:

----------------------------------------------------
class Exception
{
    Variant[string] info;
}
class FooException
{
    string fooName;
    int fooID;
    bool didBarOccur;

    this(string fooName, int fooID, bool didBarOccur)
    {
        this.fooName = fooName;
        this.fooID= fooID;
        this.didBarOccur= didBarOccur;

        info["fooName"] = fooName;
        info["fooID"] = fooID;
        info["didBarOccur"] = didBarOccur;
    }
}
----------------------------------------------------

If so, then I don't see any usefulness of "Variant[string] info" other than 
to start treating exceptions like JS's abomination of an "object" (Or at 
least AS2's objects anyway - not 100% certain how much of AS2 is taken from 
JS). If not, then could you clarify what you meant?

In either case, I am interested to hear in more detail how you see 
"Variant[string] info" being used to address i18n. I haven't really dealt 
with a lot of i18n myself.




More information about the Digitalmars-d mailing list