[Issue 704] `class` destructor is called even if constructor throws
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Jul 11 02:22:43 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=704
Denis Shelomovskij <verylonglogin.reg at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |verylonglogin.reg at gmail.com
Hardware|x86 |All
Summary|destructors are called even |`class` destructor is
|if the constructor throws |called even if constructor
|an exception |throws
OS|Linux |All
--- Comment #8 from Denis Shelomovskij <verylonglogin.reg at gmail.com> ---
---(In reply to Andrei Alexandrescu from comment #7)
> On the other hand we don't throw if a struct's ctor throws. So this is an
> inconsistency.I think it's fair in D to consider a throwing constructor as
> abandoning all construction of the object.
Also `scope` classes behaves like structs:
---
class C
{
this() { throw new Exception(""); }
~this() { assert(0); } // never called
}
void main()
{
try scope c = new C(); catch(Exception) { }
}
---
As for structs, we also have Issue 13095.
--
More information about the Digitalmars-d-bugs
mailing list