#902 – Data Available to the Handler of a Wrapped Exception

There are cases when you handle an exception by wrapping the original exception within a new exception that you then throw.  The original exception is wrapped by storing it in the InnerException property of the new exception.

When a handler further up catches the new exception, it will see the following:

  • StackTrace property shows the calling sequence only down to the method that created the new exception (the handler that caught the lower-level exception)
  • The original (wrapped) exception is accessible through the InnerException property

For example, suppose that:

  • Main method calls DoDogStuff method, which calls Dog.Bark method
  • Dog.Bark throws a DogBarkException
  • DoDogStuff catches DogBarkException, wraps the exception in an ApplicationException and throws the new exception

A handler in Main can then catch the ApplicationException and will see:

  • StackTrace of wrapped exception shows – Main called DoDogStuff
  • InnerException contains the original DogBarkException
  • StackTrace of inner exception shows – DoDogStuff called Dog.Bark

902-001

902-002

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #902 – Data Available to the Handler of a Wrapped Exception

  1. Pingback: Dew Drop – August 5, 2013 (#1,599) | Alvin Ashcraft's Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: