title: How to check if something is an .net exception or the custom exception
body: <p>Like in the question. I want to check if something on the collection of exceptions is my custom exception or is it the Exception class given by the .Net framework. Thnaks in advance for your help. \</p>
  
  <p>Please note: </p>
  
  <p>I don't know what is the class name of my custom exception it could be called exceptionA, exceptionB or for example xyzException</p>
  
  <p>I have code like this: </p>
  
  <pre class="lang-cs prettyprint-override"><code>    public IEnumerable&lt;Type&gt; GetClassHierarchy(Type type)   
      {
          if (type == null) yield break;
  
          Type typeInHierarchy = type;
  
          do
          {
              yield return typeInHierarchy;
              typeInHierarchy = typeInHierarchy.BaseType;
          }
          while (typeInHierarchy != null &amp;&amp; !typeInHierarchy.IsInterface);
      }
  
      public string GetException(System.Exception ex)
      {
          if (ex == null)
          {
              return null;
          }
  
          if (ex.InnerException == null)
          {
              return ex.Message;
          }
  
          var exceptionHerarchy = GetClassHierarchy(ex.GetType());
  
  
          var isMyException = exceptionHerarchy.Any(t =&gt; t != typeof(System.Exception));
  
          if (isMyException)
          {
              return string.Format("{0};{1}", ex.Message, GetException(ex.InnerException));
          }
          else
          {
              return GetException(ex.InnerException);
          }
  
      }        
  </code></pre>
  
  <p>var isMyException = exceptionHerarchy.Any(t => t != typeof(System.Exception)); this is alays returning true because there is this type on the list probably</p>