@nogc and exceptions

Jakob Ovrum via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 19 04:36:28 PDT 2014


On Friday, 19 September 2014 at 07:57:24 UTC, Dicebot wrote:
> I am obviously in favor of simply calling recurrent mutable 
> exception chains illegal (probably even immutable ones until we 
> fix const correctness of druntime exception handling).
>
> Reason is simple : it doesn't require any changes in existing 
> code and is exactly the way we already do it in Sociomantic :)
>
> To make it reliable Exception chain may need to be updated to 
> doubly-linked list to be able to efficiently verify that new 
> exception is not already present in the chain. I don't see any 
> costly overhead implications from that though.

That might be sufficient for a particular application like 
Sociomantic's, but it's not sufficient for library code in 
general. Such chains aren't logic errors and can easily occur in 
the wild.

The point of exception chaining is so exceptions can be thrown in 
destructors and such. In library code, these destructors don't 
know what exception is in flight, so they can only assume it 
could be any exception. If self-referencing chains were illegal 
and exceptions were statically allocated, then the conclusion is 
that these destructors can't throw anything after all, because 
that exception might already be in flight. As such, exception 
chaining would be completely useless.


More information about the Digitalmars-d mailing list