Skip to content

Instantly share code, notes, and snippets.

@kekyo
Last active November 10, 2018 06:20
Show Gist options
  • Save kekyo/abcb76d0ca4ae31c972bdf676bded123 to your computer and use it in GitHub Desktop.
Save kekyo/abcb76d0ca4ae31c972bdf676bded123 to your computer and use it in GitHub Desktop.
What kind of order did we handle exception with filter expressions.
using System;
namespace ExceptionTest
{
class Program
{
static string GetMessage(Exception ex, string banner)
{
Console.WriteLine(banner);
return ex.Message;
}
static void Main(string[] args)
{
try
{
try
{
// C D B E F H
throw new Exception("111");
// C D [Unhandled exception]
//throw new Exception("333");
}
catch (Exception ex) when (GetMessage(ex, "C") == "222")
{
Console.WriteLine("A");
}
finally
{
Console.WriteLine("B");
}
Console.WriteLine("G");
}
catch (Exception ex) when (GetMessage(ex, "D") == "111")
{
Console.WriteLine("E");
}
finally
{
Console.WriteLine("F");
}
Console.WriteLine("H");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment