#900 – What the Exception Object Contains when You Re-throw an Exception

You can re-throw an exception from within a catch block.  You typically do this when you want to catch an exception, partially handle it, but then give a method further up the stack the chance to also handle the exception.

When you use the throw statement to re-throw an exception, the Exception object will contain the same data when caught at a higher level, with one exception.  The StackTrace property will show the stack from the point where the exception was thrown, all the way up to the method where the current handler is located.

For example, suppose we have a Main method that calls a DoDogStuff method, which in turn calls a Dog.Bark method that throws an exception.  If we catch the exception within DoDogStuff, StackTrace will reflect that DoDogStuff called Dog.Bark.  If we also catch the exception in Main, the stack trace will also include Main.

900-001

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: