Small Design Guideline Update: Overriding Exception.ToString

One of the folks on my team just added a minor update to
the Design Guidelines document about overloading ToString() on Exceptions. 
As always, comments are welcome.

size=2> face="Times New Roman" size=1> style="FONT: 7pt 'Times New Roman'">           
style="FONT-WEIGHT: bold">Do override ToString when your
exception provides extra properties. "urn:schemas-microsoft-com:office:office" />

face=Verdana color=black>The code handling the custom exception may not have
caught your specific type of exception, and therefore does not have access to
the extra information unless you provide it in



Comments (4)
  1. Rick Byers says:

    Any suggestions for overriding Exception.Message?
    If the extra data you want to include is small (eg. an integer property), it seems like it would be a lot easier and safer to include it nicely in the ToString() output by overriding Message (or including it in _message during construction).

    I’m a little worried about encourraging people to override Exception.ToString this often as they may be likely to forget to include base.ToString(), or Exception.StackTrace in the output, and you’re probably not going to discover that until you (or your customer) really needs the missing information!

Comments are closed.

Skip to main content