I am currently logging errors and would like to get the most descriptive details possible. I know I can catch many different types of exceptions but what is the difference between Exception.Message
and Exception.InnerException.Message
?
Asked
Active
Viewed 3,854 times
6

FlipTop
- 161
- 1
- 2
- 8
-
See also https://stackoverflow.com/questions/2176707/exception-message-vs-exception-tostring – Michael Freidgeim May 25 '23 at 11:47
1 Answers
10
A program can catch an exception and re-raise a different exception, passing the original caught exception as the InnerException. The Exception(String, Exception)
constructor does this for example. This happens in the .NET Framework itself, TypeInitializationException, TypeLoadException, TargetInvocationException, etc are raised this way.
The inner exception is completely unrelated to the raised exception and it is very, very important that you log the inner exception as well to have any hope of diagnosing the root cause of the problem.
The simplest way to do this is to use the ToString() method on the exception object. Which provides the exception message, the stack trace and iterates through the inner exceptions. Everything you need.

Hans Passant
- 922,412
- 146
- 1,693
- 2,536
-
Now that makes sense to me! Far more info than I could have hoped for Thanks Hans. – FlipTop Mar 18 '14 at 14:02