@nogc and exceptions

Jakob Ovrum via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 12 18:53:55 PDT 2014


On Friday, 12 September 2014 at 11:38:18 UTC, Andrej Mitrovic via 
Digitalmars-d wrote:
> On 9/12/14, Jakob Ovrum via Digitalmars-d 
> <digitalmars-d at puremagic.com> wrote:
>> the chaining mechanism will
>> construct a self-referencing list that results in an infinite
>> loop when the chain is walked
>
> Can we amend the spec to say self-referencing is ok? Then we 
> could
> make the default exception handler *stop* if it finds a
> self-referencing exception (e.g. for stack traces), and for 
> custom
> user code which walks through exceptions it would either have 
> to be
> fixed.
>
> We could also provide a helper function for walking through 
> exceptions:
>
> try
> {
>     ...
> } catch (Exception ex)
> {
>     // some UFCS or object.d built-in method which
>     // stops walking when ".next is this"
>     foreach (caught; ex.walk)
>     {
>     }
> }
>
> Or does the problem have a bigger scope than just walking?

The exception chain would be unable to chain further exceptions. 
Each exception in the chain needs its own unique `next` pointer.

Also, the two links to the same exception could appear anywhere 
in the list. I think some sort of caching of exceptions already 
encountered would be required, which is a lot slower and more 
complex than the existing mechanism.


More information about the Digitalmars-d mailing list