Making an atomic transaction out of several operations I'm looking for a design pattern or suggestions that can help refactor my code into something a bit less repetitive. I have a method that has several sequential steps (10-15) that if any of them fail must record detail about the failure to a log and rollback all previous portions of the transaction. The example is below. 

I have thought about taking each try catch and turning it into an individual method but then I have to pass around my undo stack (among several other variables) and I still have to conditionally abort the method and process the undo stack. I've briefly looked into the Momento and Command patterns but both seemed to grow the line count by a fair margin. 

EnumResult TransactionThatRollsBack()
{
        var undoLog = new Stack&lt;Action&gt;();
        try
        {
            MoveInventory(inv, src, dest);
            undoLog.Push(() =&gt; MoveInventory(inv,dest,src));
        }
        catch (Exception ex)
        {
            RecordError("InventoryError", ex, inv, src, dest);
            Undo(undoLog);
            return EnumResult.FailedInventoryMove;
        }

        try
        {
            NotifyReportingOfMove(inv, user);
            undoLog.Push(() =&gt; NotifyReportingOfUnMove(inv, user));
        }
        catch (Exception ex)
        {
            RecordError("NotifyReportingOfMove", ex, inv, user);
            Undo(undoLog);
            return EnumResult.FailedReportingMove;
        }

        try
        {
            AddUserToSweepstakes(user);
            undoLog.Push(() =&gt; RemoevUserFromSweepstakes(user));

        }
        catch (Exception ex)
        {
            RecordError("AddUserToSweepstakes", ex, user);
            Undo(undoLog);
            return EnumResult.FailedSweepstakesAdd;
        }

        ...
        return EnumResult.Success
}
You can remove repeated code if you record all your actions for executions and then execute them all at once with some generic exception handling. The idea is below. 

Sorry for some possible lapses, didn't write in C# for quite some time. However I hope that you'll find the whole idea to be helpful.

  EnumResult TransactionThatRollsBack()
    {
         var undoLog = new SmartStack();
         undoLog.Push(() =&gt; MoveInventory(inv,dest,src), EnumResult.1);
         undoLog.Push(() =&gt; NotifyReportingOfUnMove(inv, user), EnumResult.2);
         undoLog.Push(() =&gt; RemoevUserFromSweepstakes(user), EnumResult.3);

         undoLog.execute();
    }

    class SmartStack {
       SortedDictionary&lt;Action, EnumResult&gt; actions; 

       void push(Action a, EnumResult r) {
         actions.add(a, r);
       }

       void execute() {
         Stack&lt;Action&gt; completedActions = new Stack&lt;Action&gt;();
         foreach(KeyValuePair&lt;Action, EnumResult&gt; pair in actions) {
             try {
               pair.Key.Invoke();
               completedActions.push(pair.Key);
             }
             catch(Exception ex) {
               for (Action a in completedActions) {
                   Undo(a);
               }
               return pair.Value;
             }
         }
       }
    }