예제 #1
0
    public ExceptionSafe()
    {
        PreciousResource tmp1 = null, tmp2 = null;
        try
        {
            tmp1 = new PreciousResource();
            tmp1.Open();
            tmp2 = new PreciousResource();
            tmp2.Open();

            // Commit point, no exception risk any more.
            resource1 = tmp1;
            tmp1 = null;
            resource2 = tmp2;
            tmp2 = null;
        }
        finally
        {
            if (tmp1 != null)
            {
                tmp1.Dispose();
            }

            if (tmp2 != null)
            {
                tmp2.Dispose();
            }
        }
    }
 public NotExceptionSafe()
 {
     resource = new PreciousResource();
     resource.Open();
 }