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

ExceptionExtensions

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