What is throwable
Denis Koroskin
2korden at gmail.com
Thu Mar 19 09:47:05 PDT 2009
On Thu, 19 Mar 2009 19:39:52 +0300, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:
> Ary Borenszweig wrote:
>> Andrei Alexandrescu wrote:
>>> 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?
>> You can't throw multiple exceptions in Java. What you can do is:
>> try {
>> ...
>> } catch(SomeException e) {
>> throw new AnotherException(e);
>> }
>> and then AnotherException is thrown with "e" being it's inner
>> exception, and you can check that.
>>
>>>
>>> Anyhow, we should implement a model in D that allows such multiple
>>> throws.
>> What for?
>
> For allowing destructors to throw.
>
> Andrei
Are you sure this is sound?
More information about the Digitalmars-d
mailing list