[Issue 14246] RAII - proper destruction of partially constructed objects/structs

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri May 19 15:45:42 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=14246

--- Comment #6 from Walter Bright <bugzilla at digitalmars.com> ---
Shachar Shemesh wrote this example:

import std.stdio;

struct A {
     int a = 3;

     this( int var ) { a += var; }

     ~this() { writeln("A down ", a); }
}

struct B {
     A a;

     this( int var ) {
         a = A(var+1);
         throw new Exception("An exception");
     }
}

void main() {
     try {
         auto b = B(2);
     } catch( Exception ex ) {
     }
}

I'd expect A's destructor to run, which does not seem to be the case.

--


More information about the Digitalmars-d-bugs mailing list