The following is a common code pattern

        Resource resource = GetResource();

        DoWork();           

        return resource;

If DoWork() throws exception, the resource will be leaked. We need to guard against this.

For example

        bool success = false;

        Resource resource = GetResource();

        try

        {

            DoWork();

            success = true;

            return resource;

        }

        finally

        {

            if (!success)

            {

                DisposeResource(resource);

            }

        }