Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, March 15, 2010 3:50 PM
I read the Exception.ToString() documentation and it mentions it shows the InnerException.ToString() details. If there are many nested inner exeptions are all the ToString() details shown?
All replies (4)
Monday, March 15, 2010 4:57 PM ✅Answered | 2 votes
When you say it returns as much info as possible... given a scenario that there is an exception thrown that has x inner exceptions will ToString() the the details of all the inner exceptions?
Yes. It prints out the inner exception information as well.
If you need more elaborate formatting, you can always loop through the extensions and build a complex string yourself (preferably using a StringBuilder). However, the default implementation of Exception.ToString() will show the exception type, message, plus any inner exceptions.
Reed Copsey, Jr. - http://reedcopsey.com
Monday, March 15, 2010 4:04 PM
Inner exception is actually as a recently patented ( http://www.patentstorm.us/patents/7028023.html ) linked list. Inner Exception derive from Exception and include pointer to another, deeper, Exception - if needed. And .ToString() try to return as much information as possibleC makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off (c) — Bjarne Stroustrup [http://www2.research.att.com/~bs/bs_faq.html#really-say-that]
Monday, March 15, 2010 4:40 PM
When you say it returns as much info as possible... given a scenario that there is an exception thrown that has x inner exceptions will ToString() the the details of all the inner exceptions?
Tuesday, September 16, 2014 12:41 PM
That is not always the case!
If a FaultException<T> is a InnerException of, for example, a System.Exception, calling the .ToString() member on the Exception does return the contents of the .ToString() of the FaultException. We have to manually check if the InnerException is a FaultException and if so manually invoke and append the result of its .ToString().
I don't know if this is a bug or not but I can tell you that it's very annoying.