I am developing a pretty extensive system in .NET, which involves a lot of system programming. Most time, I\'m using the IDisposable pattern to handle resource disposal, but
Finalizers are only needed in .NET for classes that directly own unmanaged resources (i.e. not only via an IDisposable member). Such classes must implement IDisposable using the standard pattern as described in MSDN.
The finalizer should only ever dispose unmanaged resources - the usual pattern is to call a method "protected void Dispose(bool disposing)" with the disposing argument set to false.
This method is typically implemented something like:
protected void Dispose(bool disposing)
{
if (disposing)
{
// Dispose managed resources here.
// (e.g. members that implement IDisposable)
// This could throw an exception, but will *not* be called from the finalizer
...
}
... Dispose unmanaged resources here.
... no need for any exception handling.
... Unlikely to get an exception, and if you do it will be fatal.
}
Since you are only ever disposing unmanaged resources, you generally should not be referencing any managed objects and shouldn't need to include any exception handling.