I have a class like:
class SampleRepositoryClass
{
void MethodA()
{
try
{
//do something
}
catch(Exception ex)
{
LogError(ex);
throw ex;
}
}
void MethodB(int a, int b)
{
try
{
//do something
}
catch(Exception ex)
{
LogError(ex);
throw ex;
}
}
List<int> MethodC(int userId)
{
try
{
//do something
}
catch(Exception ex)
{
LogError(ex);
throw ex;
}
}
}
In above example, you can see that in each methods (MethodA, MethodB, MethodC) have try...catch blocks to log the errors and then throw to higher level.
Imagine that when my Repository class might have more than hundred methods and in each method I have try...catch block even if there is only single line of code.
Now, my intention is to reduce these repetitive exception logging code and log all the exceptions at class level instead of method level.