Browse Source

Add pretty test for exception filters with side effects

All existing filter tests only read state; a filter that mutates a
ref local observed by the handler pins the ordering between the
filter expression and the handler body.

Assisted-by: Claude:claude-fable-5:Claude Code
pull/3857/head
Siegfried Pammer 3 days ago committed by Siegfried Pammer
parent
commit
6ae8466979
  1. 19
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs

19
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs

@ -500,6 +500,25 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -500,6 +500,25 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
#pragma warning restore CA2200 // Rethrow to preserve stack details
}
}
private static bool FilterWithSideEffect(Exception e, ref int log)
{
log++;
return e.Message.Length > 0;
}
public static void SideEffectingFilter()
{
int log = 0;
try
{
Console.WriteLine("try");
}
catch (Exception e) when (FilterWithSideEffect(e, ref log))
{
Console.WriteLine(log);
}
}
#endif
public static void ContinueInCatchInForeach(int[] arr)

Loading…
Cancel
Save