digitalmars.D.bugs - auto, delete & catch
- "Ilya Zaitseff" <sark7 mail333.com> Aug 05 2004
- "Thomas Kuehne" <eisvogel users.sourceforge.net> Aug 06 2004
Following code outputs very strange results :)
class A
{
this() { printf("A "); }
~this() { printf("~A "); throw new Exception("E"); }
}
void main()
{
try
{
auto A a = new A();
delete a; // (1)
}
catch (Exception o)
{
printf("%.*s ", o.toString());
}
}
After run, program outputs: "A ~A E ~A", i.e. A dtor is called twice.
If uncomment (1), output is "A ~A ~A ~A ... ~A", i.e. A dtor is called
many-many times :)
Aug 05 2004
Ilya Zaitseff news:opscahl7ddaaezs2 ilya.tec.amursk.ru...Following code outputs very strange results :) class A { this() { printf("A "); } ~this() { printf("~A "); throw new Exception("E"); } } void main() { try { auto A a = new A(); delete a; // (1) } catch (Exception o) { printf("%.*s ", o.toString()); } } After run, program outputs: "A ~A E ~A", i.e. A dtor is called twice. If uncomment (1), output is "A ~A ~A ~A ... ~A", i.e. A dtor is called many-many times :)
Under Linux the output is "A ~A E ~A" and "A ~A ~A Error: E" if (1) is uncommented. Note the strange difference between "E" and "Error: E" !
Aug 06 2004








"Thomas Kuehne" <eisvogel users.sourceforge.net>