private static void RunCommand(ICommand instance) { var commandRun = false; try { instance.BeforeExecute(); instance.Execute(); commandRun = true; instance.AfterExecute(); } catch (Exception exception) { instance.OnException(exception); } finally { if (!commandRun) { instance.AfterExecute(); } } }