I have the following two functions, that are nearly identical, the only difference is that one uses func
, the other action
. And I'd like to combine them into one function if it is possible.
private static void TryCatch(Action action)
{
try
{
action();
}
catch (Exception x)
{
Emailer.LogError(x);
throw;
}
}
private static TResult TryCatch<TResult>(Func<TResult> func)
{
try
{
return func();
}
catch (Exception x)
{
Emailer.LogError(x);
throw;
}
}