2
Answers

Catching Exception by Source

Marc

Marc

9y
672
1
What I am trying to accomplish is catch an exception by the actual method that's being called.  This is what I got so far, but what I found out is its only catching the exception by the namespace. 

public static void ExceptionHandler(Exception ex)
{
  if (ex.Source.Contains("Service"))
  {
  Console.WriteLine("***Warning: " + ex.Message + " Source: " + ex.Source);
  }
  if (ex.Source.Contains("SetServiceController"))
  {
  Console.WriteLine("***Error: " + ex.Message + " Source: " + ex.Source);
  }
 
  Console.WriteLine("Error: " + ex.Message + " Source: " + ex.Source);
 
}
Answers (2)