I have written a function that may throw various exceptions..
public class MyClass
{
private void Test(string param)
{
if (param.Length > 10)
throw new ArgumentException();
else if (param.Length > 20)
throw new OverflowException();
else if (string.IsNullOrWhiteSpace(param))
throw new ArgumentException();
else if (param.Length < 1)
throw new FormatException();
}
public void Call(string input)
{
try
{
Test(input);
}
catch (Exception ex)
{
HandleException(ex);
}
}
private void HandleException(Exception ex)
{
//Check if ex is of type ArgumentException
//ToDo..
//Check if ex is of type OverflowException
//ToDo...
//Check if ex is of type ArgumentException
//ToDo..
//Check if ex if of type FormatException
//ToDo..
}
}
Is it possible to have the HandleException(ex) private method so that i can handle all exceptions. Otherwise, I have to write separate exception blocks for each expcetions