#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.



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

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: