Skip to content

Commit 7a6405e

Browse files
committed
chore: modify rethrow exception logics
1 parent 415edf9 commit 7a6405e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/BenchmarkDotNet.TestAdapter/Utility/TestCaseFilter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Linq;
77
using System.Reflection;
8+
using System.Runtime.ExceptionServices;
89

910
namespace BenchmarkDotNet.TestAdapter;
1011

@@ -138,7 +139,8 @@ private bool GetTestCaseFilterExpressionFromDiscoveryContext(IDiscoveryContext d
138139
return false;
139140
}
140141

141-
throw e.InnerException ?? e;
142+
ExceptionDispatchInfo.Capture(e.InnerException ?? e).Throw();
143+
return default!;// It's required to suppress error CS0161.
142144
}
143145
}
144146
}

src/BenchmarkDotNet/Toolchains/InProcess/Emit/Implementation/Emitters/EmitExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using System.Reflection;
44
using System.Reflection.Emit;
5+
using System.Runtime.ExceptionServices;
56

67
#nullable enable
78

@@ -34,7 +35,9 @@ private static object ExecuteMethodUsingReflection<T>(T instance, string methodN
3435
}
3536
catch (TargetInvocationException wrappedByReflection)
3637
{
37-
throw wrappedByReflection.InnerException ?? wrappedByReflection;
38+
var ex = wrappedByReflection.InnerException ?? wrappedByReflection;
39+
ExceptionDispatchInfo.Capture(ex).Throw();
40+
return default!;// It's required to suppress error CS0161.
3841
}
3942
}
4043
}

0 commit comments

Comments
 (0)