August 06, 2004 auto, delete & catch | ||||
|---|---|---|---|---|
| ||||
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 :)
| ||||
August 06, 2004 Re: auto, delete & catch | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Ilya Zaitseff | 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" ! | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply