What is throwable

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Mar 19 07:59:57 PDT 2009


Steve Teale wrote:
> Daniel Keep Wrote:
> 
>>
>> Steve Teale wrote:
>>> Daniel Keep Wrote:
>>>
>>>> Steve Teale wrote:
>>>>> ...
>>>>>
>>>>> What is the point of class Throwable if you can throw any old class object?
>>>> What class Throwable?
>>> dmd\src\druntime\src\compiler\dmd\object_.d
>>>
>>>>   -- Daniel
>> Ah.
>>
>> Well, if I had to guess, I'd say it was because Throwable objects are
>> more useful than random objects of other types.  Object doesn't give you
>> msg, file, line, info or next.
>>
>>   -- Daniel
> 
> But doesn't it rather imply that if you want to be able to throw a class, then it should be derived from Throwable?

Yes, a check should be added to that effect. Later on we need to 
actually exploit that only certain types can be thrown in implementing 
exception chaining.

What is exception chaining? Consider:

void weird()
{
     scope(failure) throw new Exception1("hum");
     throw new Exception2("ho");
}

The C++ model terminates the app when an exception is thrown while the 
stack is unwound. Java (I was told without having checked) makes the 
latest exception thrown the "main" exception, and you get to also access 
the other exceptions by using primitives in class Exception. Is that true?

Anyhow, we should implement a model in D that allows such multiple 
throws. Then a few primitives defined in class Exception - e.g. next() - 
should make the entire chain accessible. At some point Walter started 
implementing that but other priorities took over. A great side project 
for anyone if you ask me :o).


Andrei



More information about the Digitalmars-d mailing list