C
cristalink
C# Language Specification 1.2 says:
<<Exceptions that occur during destructor execution are worth special
mention. If an exception occurs during destructor execution, and that
exception is not caught, then the execution of that destructor is terminated
and the destructor of the base class (if any) is called. If there is no base
class (as in the case of the object type) or if there is no base class
destructor, then the exception is discarded.>>
The exception does not seem to be discarded - the program terminates
abnormally whether B inherits A or not.
Cheers
---
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace cstest
{
class A
{
~A()
{
Console.WriteLine( "~A()" );
}
}
class B //: A
{
~B()
{
throw new Exception();
//Console.WriteLine( "~B()" );
}
public bool z = false;
}
class Program
{
static void Main( string[] args )
{
B b = new B();
b = null;
#if true
GC.Collect();
GC.WaitForPendingFinalizers();
Console.WriteLine( "OK" );
#else
int length = 2;
for( int i = 0; ; i++ )
{
Thread.Sleep( 1000 );
byte[] bb = new byte[ length ];
length *= 2;
Console.WriteLine( "OK {0} {1}", i, bb.Length );
}
#endif
}
}
}
<<Exceptions that occur during destructor execution are worth special
mention. If an exception occurs during destructor execution, and that
exception is not caught, then the execution of that destructor is terminated
and the destructor of the base class (if any) is called. If there is no base
class (as in the case of the object type) or if there is no base class
destructor, then the exception is discarded.>>
The exception does not seem to be discarded - the program terminates
abnormally whether B inherits A or not.
Cheers
---
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace cstest
{
class A
{
~A()
{
Console.WriteLine( "~A()" );
}
}
class B //: A
{
~B()
{
throw new Exception();
//Console.WriteLine( "~B()" );
}
public bool z = false;
}
class Program
{
static void Main( string[] args )
{
B b = new B();
b = null;
#if true
GC.Collect();
GC.WaitForPendingFinalizers();
Console.WriteLine( "OK" );
#else
int length = 2;
for( int i = 0; ; i++ )
{
Thread.Sleep( 1000 );
byte[] bb = new byte[ length ];
length *= 2;
Console.WriteLine( "OK {0} {1}", i, bb.Length );
}
#endif
}
}
}