digitalmars.D.bugs - auto, delete & catch
- Ilya Zaitseff (21/21) Aug 05 2004 Following code outputs very strange results :)
- Thomas Kuehne (4/25) Aug 06 2004 Under Linux the output is "A ~A E ~A" and "A ~A ~A Error: E" if (1) is
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>