Often I find that the most valuable error information is contained in the most inner exception. This should be simple but how can I iterate through the inner exceptions to get to the root of the problem?
static void ShowExceptionChain(Exception ex) { int num = 1; do { Console.WriteLine("{0}. {1}", num, ex); num++; ex = ex.InnerException; } while (ex != null); } }
However, if you want to go directly to the innermost exception you can just call the GetBaseException method.
1 answers
You can iterate through the inner exceptions as follows:
However, if you want to go directly to the innermost exception you can just call the GetBaseException method.
answered one year ago by:
17279