I found that in my code there is a lot of this in different methods:
try
{
runABunchOfMethods();
}
catch (Exception ex)
{
logger.Log(ex);
}
How about creating this:
public static class Executor
{
private static ILogger logger;
public delegate void ExecuteThis();
static Executor()
{
}
public static void Execute<T>(ExecuteThis executeThis)
where T : Exception
{
try
{
executeThis();
}
catch (T ex)
{
logger.Log(ex);
}
}
}
And just using it like this:
private void RunSomething()
{
Method1(someClassVar);
Method2(someOtherClassVar);
}
...
Executor.Execute<ApplicationException>(RunSomething);
Are there any flaws in this approach? (You can add Executor methods and delegates when you want to finally use and use generics for the type of Exeception you want to catch ...)
: - , , , , , , , , , / . try.../runABunchOfMethods-part ( ), runABunchOfMethods, , , " ".
, / , .
Executor, T, exeception , , . catch: es , , , .