<PackageReference Include="Polly" Version="7.0.2" />

ExceptionExtensions

public static class ExceptionExtensions
Contains extension methods on the Exception class.
using System; using System.Runtime.ExceptionServices; namespace Polly.Utilities { public static class ExceptionExtensions { public static void RethrowWithOriginalStackTraceIfDiffersFrom(this Exception exceptionPossiblyToThrow, Exception exceptionToCompare) { if (exceptionPossiblyToThrow != exceptionToCompare) ExceptionDispatchInfo.Capture(exceptionPossiblyToThrow).Throw(); } } }