Find the inner-most exception without using a while loop?

前端 未结 12 740
南旧
南旧 2020-12-12 18:54

When C# throws an exception, it can have an inner exception. What I want to do is get the inner-most exception, or in other words, the leaf exception that doesn\'t have an i

12条回答
  •  [愿得一人]
    2020-12-12 19:18

    Looping through InnerExceptions is the only reliable way.

    If the caught exception is an AggregateException, then GetBaseException() returns only the innermost AggregateException.

    http://msdn.microsoft.com/en-us/library/system.aggregateexception.getbaseexception.aspx

提交回复
热议问题