0

If I traverse an Exception graph, via InnerException and InnerExceptions (for AggregateExceptions), is it possible that the graph could be recursive? I wouldn't think so, since the inner exceptions must be assigned in the constructor and therefore must already exist.

Triynko
  • 18,766
  • 21
  • 107
  • 173
  • https://stackoverflow.com/questions/18489387/what-is-the-best-practice-for-capturing-all-inner-exception-details – Rick S Oct 11 '18 at 18:42
  • You mean cyclic, containing a cycle, it is most definitively recursive. – Lasse V. Karlsen Oct 11 '18 at 19:06
  • I mean recursive, as in if I traverse the graph, will it result in infinite recursion. The fact that ToString does not infinitely recurse, yet includes the information of inner exceptions, suggests that it is definitely not recursive. – Triynko Oct 12 '18 at 22:54
  • If you look at the source code for Exception, the _innerException property is only assigned in two places. One is in the constructor. If that were the only place, then any InnerException would have to pre-date the existence of its parent, resulting in a directed graph that cannot contain cycles. However, it's also assigned in the constructor for deserialization that takes a streaming context. As far as I know, I could modify the serialized stream to simulate a graph that would result in recursion. This would probably break the runtime behavior of ToString anyway. – Triynko Oct 12 '18 at 23:01

0 Answers0