#879 – Unhandled Exceptions in Finalizers

Like other unhandled exceptions, an exception that is thrown from a finalizer and not handled will cause your application to terminate.

~Dog()
{
    Console.WriteLine(
       "Dog finalizer is running.  I'll throw an exception and your app will terminate");
    throw new Exception("Dang it");
}
Dog d = new Dog("Kirby", 15);
d.Bark();

d = null;
GC.Collect();

879-001

Advertisement