Detecting exception unwinding

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 3 03:41:28 PST 2016


On Wednesday, February 03, 2016 11:09:00 Ola Fosheim Grøstad via Digitalmars-d-learn wrote:
> Is there some reliable way to detect that a destructor is called
> because of exception unwinding?
>
> I basically want to change behaviour within a destructor based on
> whether the destructor is called as a result of a regular or an
> exceptional situation.
>
> E.g. commit changes to a database on regular destruction, or
> inhibit logging during exception unwinding.

AFAIK, there is no way to detect whether an exception is in flight or not
aside from the cases where scope(failure) or catch would catch the
exception, and from what I recall of the last time that someone asked this
question, the consensus was that it couldn't be done - but maybe I'm
remembering incorrectly. I am pretty sure that this was asked within the
last few months though, so if you search D.Learn, you can probably find that
discussion.

- Jonathan M Davis




More information about the Digitalmars-d-learn mailing list