Exception chaining and collectException

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 21 11:08:01 PDT 2017


On Sat, Aug 19, 2017 at 08:58:51PM +0000, Nemanja Boric via Digitalmars-d wrote:
> On Friday, 18 August 2017 at 22:51:35 UTC, Walter Bright wrote:
> > On 8/18/2017 5:07 AM, Steven Schveighoffer wrote:
> > > If we are to remove them, what happens when exceptions would
> > > normally chain?
> > 
> > In C++, throwing an exception while unwinding is a fatal error.
> > 
> 
> Well, you still can throw it, but you're not allowed to let it escape
> the destructor (you need to catch them before they would chain).

This was what I was trying to do: wrap some code in a try-catch in the
dtor so that any exceptions thrown won't escape the dtor.

However, the current inconsistent behaviour is making this difficult.
The same dtor behaves differently depending on whether it was called
from a normal end of scope, or while an Exception is in transit.  I.e.,
when called normally, the catch clause catches MyException, but when
another Exception is in transit, the catch clause fails to catch
MyException (yet it does catch the base class Exception, a rather
strange behaviour).


T

-- 
The most powerful one-line C program: #include "/dev/tty" -- IOCCC


More information about the Digitalmars-d mailing list