Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8824011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:30:05+00:00 2026-06-14T06:30:05+00:00

I’m using a test framework that reports exceptions using Exception.ToString(). I ran into incomplete

  • 0

I’m using a test framework that reports exceptions using Exception.ToString().

I ran into incomplete reporting of nested exceptions yesterday, and after some work with Reflector came to the conclusion that .NET 4.0 has broken how inner exception string representations are composed.

Here’s an example;

public class MyException : Exception
{
  DateTime when;

  public MyException(DateTime when)
  {
    this.when = when;
  }

  public override string ToString()
  {
    var builder = new StringBuilder();
    builder.AppendFormat("Happened at: {0}\r\n", this.when);
    builder.Append(base.ToString());
    return builder.ToString();
  }
}

class Program
{
  private static void throws()
  {
    throw new Exception("bobby!", new MyException(DateTime.Now));
  }

  private static void catches()
  {
    try
    {
      throws();
    }
    catch (Exception e)
    {
      Console.WriteLine(e);
    }
  }

  static void Main(string[] args)
  {
    catches();
  }
}

The console output here will not contain my custom “Happened at” prefix.

Note that if we throw MyException directly, not nested in another exception, the custom string rep will be used.

It turns out the reason is that Exception.ToString() no longer calls the inner exception’s ToString(), but rather a private method, ToString(bool), i.e.

// Exception
public override string ToString()
{
  return this.ToString(true);
}

private string ToString(bool needFileLineInfo)
{
  // yada yada

  if (this._innerException != null)
  {
    result += "some stuff " + this._innerException.ToString(needFileLineInfo) + " some more stuff";
                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
  }

  // yada yada

  return result;
}

So, since Exception.ToString() no longer calls the inner exception’s ToString(), the implementation has short-circuited any opportunity of customized string representations for inner exceptions.

In .NET 2.0, the overridable ToString() was called as expected, so this was a breaking change somewhere along the way.

The docs haven’t changed, and still claim that;

The default implementation of ToString obtains the name of the class
that threw the current exception, the message, the result of calling
ToString on the inner exception […]

http://msdn.microsoft.com/en-us/library/system.exception.tostring.aspx

Does this sound like a bug to anyone but me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:30:06+00:00Added an answer on June 14, 2026 at 6:30 am

    Yes, it appears to be a bug. Have a look at MS Connect issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.