I have a class with number of methods and want to have one exception handler for them all. There are so many of these methods and they have different parameters, that it would b
You could use a delegate to pass your method's code into a single try catch like the following example:
private void GlobalTryCatch(Action action)
{
try
{
action.Invoke();
}
catch (ExpectedException1 e)
{
throw MyCustomException("Something bad happened", e);
}
catch (ExpectedException2 e)
{
throw MyCustomException("Something really bad happened", e);
}
}
public void DoSomething()
{
GlobalTryCatch(() =>
{
// Method code goes here
});
}