Exception chaining and collectException

Don Clugston via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 18 02:09:47 PDT 2017


On Friday, 18 August 2017 at 03:31:38 UTC, Walter Bright wrote:
> Chained exceptions are a good idea, but are more or less a 
> disaster:
>
> 1. No other language does chained exceptions
>
> 2. Attempting to hammer D chained exceptions into other 
> language schemes (such as C++) makes for lots of unfun hours 
> attempting to decode undocumented behavior in those other 
> schemes
>
> 3. Makes D exceptions incompatible with other language 
> exceptions and their infrastructure
>
> 4. Are incomprehensibly implemented (I defy anyone to explain 
> how the test cases in the test suite are actually supposed to 
> work)

Well, I wrote them, so I can explain that. The problem is that 
the idea that you can form a "chain" of exceptions turns out to 
be naive.

What if a chained exception needs to get chained to another 
chained exception? And that then needs to be chained to another 
exception?
It forms a tree! That's why the test cases are so complicated.

So to a large extent, this extremely obscure corner case destroys 
the elegance of the concept.

Secondly, exception handling in windows is practically 
undocumented. Certainly it's not documented in a single place. 
When I began to implement it, I feared it might be impossible. 
There isn't any guarantee that exception chaining can actually be 
implemented on all platforms.

> 5. Are more or less incompatible with non-GC memory allocation
>
> I'd like to remove them from D.
>
> I recommend *not* designing any program that requires them.

I invested quite a lot personally in implementing chained 
exceptions. But I agree with you.
I was actually quite proud that I worked out the nasty corner 
cases during the initial implementation. As far as I can tell, 
problems with chained exceptions are not because of bugs and 
implementation issues, but because of problems with the concept 
itself.

I think it's just a bit too clever.




More information about the Digitalmars-d mailing list