Index: /trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.cpp	(revision 45278)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.cpp	(revision 45279)
@@ -1999,45 +1999,50 @@
         const QStringList &oldGroupList = m_oldLists.value(strId);
         const UIStringSet &oldGroupSet = UIStringSet::fromList(oldGroupList);
-        /* Is group set changed? */
-        if (newGroupSet != oldGroupSet)
-        {
-            /* Open session to modify iterated machine: */
-            CSession session = vboxGlobal().openSession(strId);
+        /* Make sure group set was changed: */
+        if (newGroupSet == oldGroupSet)
+            continue;
+
+        /* The next steps are subsequent.
+         * Every of them is mandatory in order to continue
+         * with common cleanup in case of failure.
+         * We have to simulate a try-catch block. */
+        bool fSuccess = false;
+        CSession session;
+        CMachine machine;
+        do
+        {
+            /* 1. Open session: */
+            session = vboxGlobal().openSession(strId);
             if (session.isNull())
-            {
-                emit sigReload(strId);
-                continue;
-            }
-
-            /* Get session machine: */
-            CMachine machine = session.GetMachine();
-            AssertMsg(!machine.isNull(), ("Session machine is NULL!"));
+                break;
+
+            /* 2. Get session machine: */
+            machine = session.GetMachine();
             if (machine.isNull())
-            {
-                emit sigReload(strId);
-                continue;
-            }
-
-            /* Set groups: */
+                break;
+
+            /* 3. Set new groups: */
             machine.SetGroups(newGroupList.toVector());
             if (!machine.isOk())
-            {
-                msgCenter().cannotSetGroups(machine);
-                emit sigReload(strId);
-                continue;
-            }
-
-            /* Save settings: */
+                break;
+
+            /* 4. Save settings: */
             machine.SaveSettings();
             if (!machine.isOk())
-            {
+                break;
+
+            /* Transaction complete: */
+            fSuccess = true;
+        } while (0);
+
+        /* Cleanup if necessary: */
+        if (!fSuccess)
+        {
+            if (!machine.isNull())
                 msgCenter().cannotSaveMachineSettings(machine);
-                emit sigReload(strId);
-                continue;
-            }
-
-            /* Close the session finally: */
+            emit sigReload(strId);
+        }
+        if (!session.isNull())
             session.UnlockMachine();
-        }
     }
 
