C#C
C#6d ago
Ruttie

Exceptions in finalizer

I want to run some debug assertions to check if an object was disposed properly by checking state.
The easiest way I can see to do so is in the finalizer.
I would have something like this:
#if DEBUG
~MyClass() {
    Debug.Assert(condition);
}
#endif

My question is, is it safe to throw exceptions in finalizers?
Should I be worried about the GC ending up in a weird state?
Was this page helpful?