destructors
Daniel Giddings
danielg at microforte.com
Tue May 1 20:58:01 PDT 2007
>
> I thought exceptions thrown in a destructor got ignored?
>
> -- Daniel
>
The test below gives the following result:
this
~this
Error: ~this without .destroy
at least with dmd 1.007 in windows...
:-) Dan
--
import std.stdio;
class OtherClass
{
this() { writefln( "this" ); }
~this() { writefln( "~this" ); }
}
class MyClass
{
OtherClass a;
bool destroyed = false;
this() { a = new OtherClass; }
~this() { if( !destroyed ) throw new Exception( "~this without
.destroy" ); }
MyClass destroy() { delete a; destroyed = true; delete this; return null; }
}
void main()
{
MyClass m = new MyClass;
}
More information about the Digitalmars-d-learn
mailing list