using System;
public class Test
{
private static bool Flag = false;
static void Main(string[] args)
{
Console.WriteLine("Start");
try
{
SomeOperation();
}
catch (Exception) when (EvaluatesTo())
{
Console.WriteLine("Catch");
}
finally
{
Console.WriteLine("Outer Finally");
}
}
private static bool EvaluatesTo()
{
Console.WriteLine($"EvaluatesTo: {Flag}");
return true;
}
private static void SomeOperation()
{
try
{
Flag = true;
throw new Exception("Boom");
}
finally
{
Flag = false;
Console.WriteLine("Inner Finally");
}
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIFRlc3QKewoJcHJpdmF0ZSBzdGF0aWMgYm9vbCBGbGFnID0gZmFsc2U7CgkKCXN0YXRpYyB2b2lkIE1haW4oc3RyaW5nW10gYXJncykKCXsKCSAgICBDb25zb2xlLldyaXRlTGluZSgiU3RhcnQiKTsKCSAgICB0cnkKCSAgICB7CgkgICAgICAgIFNvbWVPcGVyYXRpb24oKTsKCSAgICB9CgkgICAgY2F0Y2ggKEV4Y2VwdGlvbikgd2hlbiAoRXZhbHVhdGVzVG8oKSkKCSAgICB7CgkgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCJDYXRjaCIpOwoJICAgIH0KCSAgICBmaW5hbGx5CgkgICAgewoJICAgICAgICBDb25zb2xlLldyaXRlTGluZSgiT3V0ZXIgRmluYWxseSIpOwoJICAgIH0KCX0KCQoJcHJpdmF0ZSBzdGF0aWMgYm9vbCBFdmFsdWF0ZXNUbygpCgl7CgkgICAgQ29uc29sZS5Xcml0ZUxpbmUoJCJFdmFsdWF0ZXNUbzoge0ZsYWd9Iik7CgkgICAgcmV0dXJuIHRydWU7Cgl9CgkKCXByaXZhdGUgc3RhdGljIHZvaWQgU29tZU9wZXJhdGlvbigpCgl7CgkgICAgdHJ5CgkgICAgewoJICAgICAgICBGbGFnID0gdHJ1ZTsKCSAgICAgICAgdGhyb3cgbmV3IEV4Y2VwdGlvbigiQm9vbSIpOwoJICAgIH0KCSAgICBmaW5hbGx5CgkgICAgewoJICAgICAgICBGbGFnID0gZmFsc2U7CgkgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCJJbm5lciBGaW5hbGx5Iik7CgkgICAgfQoJfQp9