Example #1
0
 public void Main()
 {
     try
     {
         using (var obj = MyObj.Create())
         {
             var message = obj.ReadMessage();
             Console.WriteLine(message);
         }
     }
     catch (Exception ex)
     {
         // Everything is already cleaned up by the using statement.
         Console.WriteLine(ex.Message);
     }
 }
Example #2
0
 public void Main()
 {
     try
     {
         using (var obj = MyObj.Create())
         {
             // everything is already in a valid state.
             var message = obj.ReadMessage();
             Console.WriteLine(message);
         }
     }
     catch (Exception ex)
     {
         // If the factory succeeded, the using statement did the cleanup.
         // if the factory failed, the factory took care of the cleanup.
         Console.WriteLine(ex.Message);
     }
 }