This is just a short description of my thoughts of handling exceptions and at the same time offering a retry.
I created an extension method just to make it convenient to use. The method extends an Action so that you just have to call
(Action).TryRepeat(method) with a method that returns a Boolean to indicate if the action should retry or not.
public static void TryRepeat(this Action action, Func<Exception, bool> failAction)
catch (Exception e)
if (Debugger.IsAttached) Debugger.Break();
repeat = failAction(e);
} while (repeat);
To use the extension method you can do this:
Action a = () =>
The evaluation function takes the Exception as input and returns a Boolean value to indicate if the action should be repeated.
It could look like this:
public static bool HandleException(Exception e)
if (e is SomeException)
MessageBoxResult result =
MessageBox.Show("Connection seems lost, reconnect?", "Error",
return result == MessageBoxResult.Yes;
Points of Interest
I'm not thrilled about my idea, mainly because retrying actions might provoke unforeseen errors.
- 1.0: My initial thoughts.