import std.stdio; struct S(alias n) { this(int) { throw new Exception("Exception"); } ~this() { writeln("destructor " ~ n); } }
void main() { writeln("--- 1 ---"); try { auto s = S!"1"(0); } catch (Exception) {} writeln("--- 2 ---"); try { auto s = new S!"2"(0); } catch (Exception) {} } Output: --- 1 --- --- 2 --- destructor 2Why the destructor is called in the second case and why not in the first?
How to design structs with such different behavior?