I need to catch a generic exception and then categorize is based on a specific type to reduce the no of lines of code as all the exception does the same thing .
Something like below
catch (Exception ex)
{
Type ExceptionType = ex.GetType();
switch (ExceptionType.ToString())
{
case "IOException":
case "NullReferenceException":
system.WriteLine((ExceptionType)ex.Message);
break;
}
This shows error there is no type Exception type. Is there a possiblity to try this approach and accomplish this or need to take a typical if else approach. Please help