scope() statements and return

monarch_dodra via Digitalmars-d digitalmars-d at puremagic.com
Mon Oct 6 07:24:00 PDT 2014


On Monday, 6 October 2014 at 13:48:07 UTC, Andrei Alexandrescu 
wrote:
> On 10/6/14, 12:27 AM, Walter Bright wrote:
>> On 10/5/2014 10:09 AM, Dicebot wrote:
>>> On Sunday, 5 October 2014 at 17:03:07 UTC, Andrei 
>>> Alexandrescu wrote:
>>>> On 10/5/14, 9:42 AM, Dicebot wrote:
>>>>> On Sunday, 5 October 2014 at 16:30:47 UTC, Ola Fosheim 
>>>>> Grøstad wrote:
>>>>>> Does D have exception chaining?
>>>>>
>>>>> Yes. http://dlang.org/phobos/object.html#.Throwable.next
>>>>> Though it seems to do more harm then good so far.
>>>>
>>>> What harm does it do? -- Andrei
>>>
>>> Good chunk of issues with pre-allocated exceptions (and 
>>> possible
>>> cycles in
>>> reference counted ones) comes from the chanining possibility. 
>>> At the
>>> same time I
>>> have yet to see it actively used as a feature.
>>>
>>> Doesn't mean it is bad thing, just not used wide enough to 
>>> compensate for
>>> trouble right now.
>>
>> FWIW, I'm skeptical as well of the value of chaining relative 
>> to its
>> cost in complexity.
>
> It's one of those designs in which there's little room to turn. 
> We wanted to (a) allow destructors to throw, (b) conserve 
> information. Offering access to all exceptions caught was a 
> natural consequence. -- Andrei

Well, then again, even that promise isn't really held.

If your "catch" throws an exception, then the new exception 
simply "squashes" replaces the old one:

//----
catch (Exception e)
{
     thisMightThrow(); //Lose "e" here
     throw e;
}
//----

I've seen literally no-one ever chain exceptions once one has 
been caught. Not even druntime does it. For example, if an 
exception occurs during a static array construction, this 
triggers the destruction of already constructed items. If one of 
*those* fails, then the cleanup loop terminates (without cleaning 
the rest of the items mind you). And the user is greeted with a 
"Object destruction failed", even though the array was never 
constructed to begin with!

There's merit in the goal, but I don't think the current design 
has achieved it.


More information about the Digitalmars-d mailing list