This project has moved. For the latest updates, please go here.
ExceptionHelpers

There is one static method on the ExceptionHelpers type:

Exception PrepareForRethrow(Exception exception);

The purpose of this method is to preserve the original stack trace of the exception so that it is not overwritten when the exception is rethrown.

The return value of this method should always be thrown immediately; that is, every call to this method should look like this:

Exception ex = ...; // get saved exception
throw ExceptionHelpers.PrepareForRethrow(ex);

PrepareForRethrow will use ExceptionDispatchInfo if it is running on a machine with .NET 4.5 installed. If only .NET 4.0 is available, this method will fall back to the undocumented but somewhat common reflection hack of calling Exception.PrepForRemoting. If both of these approaches fail (which may happen in Silverlight 5 or partial-trust .NET 4.0 scenarios), the original stack trace is added to the Data property of the exception.

Last edited Sep 30, 2012 at 3:32 PM by StephenCleary, version 1

Comments

No comments yet.