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
?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With