Marc

Marc

  • 1.9k
  • 205
  • 46.6k

Catching Exception by Source

Jan 23 2015 8:31 AM
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)