I have several methods that look like this:
public void foo()
{
try
{
doSomething();
}
catch(Exception e)
{
Log.Error(e);
}
}
If you don't want to use an AOP approach, a method used at one of my previous employers for common exception handling across a set of class was to have a base class with a method similar to the following
protected TResult DoWrapped(Func action)
{
try
{
return action();
}
catch (Exception)
{
// Do something
throw;
}
}
With methods looking like.
public object AMethod(object param)
{
return DoWrapped(() =>
{
// Do stuff
object result = param;
return result;
});
}
Can't remember exactly, it's been a while. But similar to this.