Struct field destructor not called when exception is thrown in the main struct destructor

Steven Schveighoffer schveiguy at
Fri Oct 16 16:00:07 UTC 2020

On 10/16/20 9:12 AM, tchaloupka wrote:

> So when the exception is thrown within Foo destructor (and it's bad on 
> it's own but can easily happen as destructors aren't nothrow @nogc by 
> default).
> Is this behavior expected?

I would say it's a bug. The compiler is going to call the member 
destructor even if the hand-written destructor does it too. If the 
compiler wants to take responsibility for cleaning up members, it should 
take full responsibility. In fact, there is no way to instruct the 
compiler "I'm handling the destruction of this member", so I don't see 
why it should matter if you exit the function via exception it should be 
any different.


More information about the Digitalmars-d-learn mailing list