Skip to content

Latest commit

 

History

History
18 lines (17 loc) · 633 Bytes

README.md

File metadata and controls

18 lines (17 loc) · 633 Bytes

GuardedDisposable

Since IDisposables are usually used in an using block, they create a try-finally which might swallow an exception if the IDisposable's implementation throws an Exception in the Dispose method. GuardedDisposables ensures those Exceptions will not get lost.

Usage

try
{
    using (var guardedDisposable = new ThirdPartyDisposable().Guard())
    {
        guardedDisposable.Execute(d => d.Foo());
    }
}
catch (GuardedDisposableException guardedDisposableException)
{
    HandleExeption(guardedDisposableException.ExecutionException);
    HandleExeption(guardedDisposableException.DisposeException);
}