www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Exceptions part 2: Incomplete objects

reply Sean Kelly <sean f4.ca> writes:
# /*
#  This example demonstrates that the dtors of incomplete
#  objects are called during a GC run.
#  */
#  
#  import std.c.stdio;
#  import std.gc;
# 
# class IC
# {
#     this()
#     {
#         printf( "IC ctor\n" );
#         throw new Exception( "IC Exception" );    
#     }
#     
#     ~this()
#     {
#         printf( "IC dtor\n" );    
#     }
# }
# 
# void main()
# {    
#     try
#     {   
#         IC ic = new IC();
#         printf( "success\n" );
#     }
#     catch( Exception e )
#     {
#         printf( "fail: %.*s\n", e.toString() );    
#     }
#     fullCollect();
#     printf( "done\n" );
# }

Output:

IC ctor
fail: IC Exception
IC dtor
done
Apr 13 2005
parent Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sean Kelly schrieb am Thu, 14 Apr 2005 05:39:32 +0000 (UTC):
 # /*
 #  This example demonstrates that the dtors of incomplete
 #  objects are called during a GC run.
 #  */
 #  
 #  import std.c.stdio;
 #  import std.gc;
 # 
 # class IC
 # {
 #     this()
 #     {
 #         printf( "IC ctor\n" );
 #         throw new Exception( "IC Exception" );    
 #     }
 #     
 #     ~this()
 #     {
 #         printf( "IC dtor\n" );    
 #     }
 # }
 # 
 # void main()
 # {    
 #     try
 #     {   
 #         IC ic = new IC();
 #         printf( "success\n" );
 #     }
 #     catch( Exception e )
 #     {
 #         printf( "fail: %.*s\n", e.toString() );    
 #     }
 #     fullCollect();
 #     printf( "done\n" );
 # }
Known bug http://dstress.kuehne.cn/run/destructor_04.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCXx4B3w+/yD4P9tIRAn0zAJ0Wuqm4deW0v84PXtU5hcHcfTzTFwCfbFhP +Fna+zTWf5cXBc+c87J/+ok= =VCl/ -----END PGP SIGNATURE-----
Apr 14 2005