public static void TryRun(Action <string> code, string argument, Editor editor) { TryRun(code: null, codeWithArgument: code, argument: argument, editor: editor); }
private static void TryRun(Action code, Action <string> codeWithArgument, string argument, Editor editor) { if (editor != null && editor.IsDirty) { MessageBox.Show("The editor has unsaved changes; cannot continue with this operation!", App.GetName() + " · Unsaved Changes", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { bool retry = true; bool retried = false; while (retry) { try { if (argument == null) { code(); } else { codeWithArgument(argument); } retry = false; } catch (Exception e) { string message = string.Format("The following exception occurred:\n\n{0}", e.Message); if (retried) { message += string.Format("\n\n{0}", e.StackTrace.ToString()); } if (MessageBox.Show(message, App.GetName() + " · Exception", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) == DialogResult.Cancel) { retry = false; } else { retried = true; } } } } }
public static void TryRun(Action code, Editor editor) { TryRun(code: code, codeWithArgument: null, argument: null, editor: editor); }