I'm recursively iterating through an object's properties using the following method:

```
void GetProps(object obj)
{
    if (obj == null)
        return;

    var objType = obj.GetType();
    var properties = objType.GetProperties();

    foreach (var property in properties)
    {
        object value = property.GetValue(obj, null);

        if (typeof(IEnumerable).IsAssignableFrom(property.PropertyType))
        {
            var enumerable = (IEnumerable)value;

            foreach (object child in enumerable)
                GetProps(child);
        }
        else
        {
            GetProps(value);
        }
    }
}

```

The object is very complex (over 30 classes). I'm getting a `StackOverflowException` when going deeper into the object at `GetProps(value`.

Is there a way to catch the exception and check why it's failing, and, solve the problem?

**EDIT**

I added a fail-safe at the top of the method:

```
if (visited.Contains(obj))
    return;

visited.Add(obj);

```

The problem is not with circular references (which I don't have) but with property types such as `DateTime`, `int` and `decimal`. which was assuming they're primitive but the `IsPrimitive` property is `false`.

Can I differentiate between such types and my own classes?