[Issue 704] New: destructors are called even if the constructor throws an exception
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Dec 21 07:21:46 PST 2006
http://d.puremagic.com/issues/show_bug.cgi?id=704
Summary: destructors are called even if the constructor throws an
exception
Product: D
Version: 0.177
Platform: PC
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: thomas-dloop at kuehne.cn
(originally posted by Sean Kelly <sean at f4.ca> on 2006-01-24 as
news:dr5uqg$2hn7$1 at digitaldaemon.com)
// This demonstrates incorrect behavior for auto class
// construction. If an exception is thrown out of a
// class ctor then it is an incomplete object and its
// dtor should not be called.
import std.c.stdio;
auto class AutoClass
{
public:
this()
{
printf( "ctor\n" );
throw new Exception( "" );
}
~this()
{
printf( "dtor\n" );
}
}
void main()
{
try
{
auto AutoClass c = new AutoClass();
}
catch( Exception e )
{
printf( "caught\n" );
}
printf( "continue\n" );
}
C:\code\d\bugs>dmd 101_1.d
C:\bin\dmd\bin\..\..\dm\bin\link.exe 101_1,,,user32+kernel32/noi;
C:\code\d\bugs>101_1
ctor
caught
continue
dtor
test cases:
http://dstress.kuehne.cn/run/a/auto_14_A.d
http://dstress.kuehne.cn/run/a/auto_14_B.d
--
More information about the Digitalmars-d-bugs
mailing list