#857 – What an Exception Object Contains

When some code throws an exception, it creates an instance of System.Exception or one of its derived classes and populates the exception object with information that might help understand what went wrong.  The runtime environment also writes some information into the exception object.

In an exception handler, you’ll have access to the information stored within the Exception object.  Listed below are the properties of this type that you can use to get information about the exception.

Always populated:

  • Message – A message summarizing the error
  • StackTrace – A multiline string, describing the current call stack, at the time of the error
  • Source – Name of the assembly where the error originated
  • TargetSite – Information about the method that threw the exception (MethodBase)

Sometimes populated:

  • InnerException – An earlier exception that triggered the current exception  (optional)
  • Data – A series of keyword/value pairs, with additional information about the error  (optional)
  • HelpLink – Link to associated help file  (optional)
Advertisement