fork(9) download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. private static bool Flag = false;
  6.  
  7. static void Main(string[] args)
  8. {
  9. Console.WriteLine("Start");
  10. try
  11. {
  12. SomeOperation();
  13. }
  14. catch (Exception) when (EvaluatesTo())
  15. {
  16. Console.WriteLine("Catch");
  17. }
  18. finally
  19. {
  20. Console.WriteLine("Outer Finally");
  21. }
  22. }
  23.  
  24. private static bool EvaluatesTo()
  25. {
  26. Console.WriteLine($"EvaluatesTo: {Flag}");
  27. return true;
  28. }
  29.  
  30. private static void SomeOperation()
  31. {
  32. try
  33. {
  34. Flag = true;
  35. throw new Exception("Boom");
  36. }
  37. finally
  38. {
  39. Flag = false;
  40. Console.WriteLine("Inner Finally");
  41. }
  42. }
  43. }
Success #stdin #stdout 0.04s 23928KB
stdin
Standard input is empty
stdout
Start
EvaluatesTo: True
Inner Finally
Catch
Outer Finally