#900 – What the Exception Object Contains when You Re-throw an Exception
August 1, 2013 Leave a comment
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.