Java also has chained exceptions, done manually

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Sep 6 23:34:20 UTC 2018


On 9/6/18 1:13 PM, Neia Neutuladh wrote:
> The actual structure of the exceptions: `primary` has children `scope 2` 
> and `scope 1`; `scope 2` has child `cause 2`; `scope 1` has child `cause 
> 1`. A tree.

No, it's a list.

> The encoded structure: a linked list where only the first two positions 
> have any structure-related meaning and the rest are just a sort of 
> mish-mash.
> 
> This isn't a situation you get in Java because Java doesn't have a way 
> to enqueue multiple independent actions at the end of the same block. 
> You just have try/finally and try(closeable).
> 
>> (As an aside, it does seem we could allow some weird cases where 
>> people rethrow some exception down the chain, thus creating loops. 
>> Hopefully that's handled properly.)
> 
> Not if you semi-manually create the loop:
> 
> auto e = new Exception("root");
> scope (exit) throw new Exception("scope 1", e);
> throw e;
> 
> Filed as https://issues.dlang.org/show_bug.cgi?id=19231

Thanks!


Andrei


More information about the Digitalmars-d mailing list